/
servlamo
/
cue
Обзор
Документация
Войти
/
servlamo
/
cue
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tools/flow/example_basic_test.go
58 строк
1 KB
Marcel van Lohuizen
tools/flow: get rid of deprecated cue.Runtime
21 июн 2022, 15:36
21 июн 2022, 15:36
3ac85dc
Код
Авторство
О чём код?
package flow_test import ( "context" "fmt" "log" "cuelang.org/go/cue" "cuelang.org/go/cue/cuecontext" "cuelang.org/go/tools/flow" ) func Example() { ctx := cuecontext.New() v := ctx.CompileString(` a: { input: "world" output: string } b: { input: a.output output: string } `) if err := v.Err(); err != nil { log.Fatal(err) } controller := flow.New(nil, v, ioTaskFunc) if err := controller.Run(context.Background()); err != nil { log.Fatal(err) } // Output: // setting a.output to "hello world" // setting b.output to "hello hello world" } func ioTaskFunc(v cue.Value) (flow.Runner, error) { inputPath := cue.ParsePath("input") input := v.LookupPath(inputPath) if !input.Exists() { return nil, nil } return flow.RunnerFunc(func(t *flow.Task) error { inputVal, err := t.Value().LookupPath(inputPath).String() if err != nil { return fmt.Errorf("input not of type string") } outputVal := fmt.Sprintf("hello %s", inputVal) fmt.Printf("setting %s.output to %q\n", t.Path(), outputVal) return t.Fill(map[string]string{ "output": outputVal, }) }), nil }