ImportPath string Dir string PkgName string DisplayName string
Incomplete bool// true if Pkg and all its dependencies are free of errors Err errors.Error // non-nil if the package had errors
inst *build.Instance }
和
1 2 3 4 5 6 7
type Value struct { idx *runtime.Runtime v *adt.Vertex // Parent keeps track of the parent if the value corresponding to v.Parent // differs, recursively. parent_ *parent }
所以我们用CompileString函数 他返回了一个value类型的值
1 2 3 4 5 6 7 8
// CompileString parses and build a Value from the given source string. // // The returned Value will represent an error, accessible through Err, if any // error occurred. func(c *Context)CompileString(src string, options ...BuildOption)Value { cfg := c.parseOptions(options) return c.compile(c.runtime().Compile(&cfg, src)) }
第三个参数是个函数 type TaskFunc func(v cue.Value) (Runner, error) 只要实现了这种函数形式就可以 后面的runner是个interface flow自己提供了一个实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
type Runner interface { // Run runs a Task. If any of the tasks it depends on returned an error it // is passed to this task. It reports an error upon failure. // // Any results to be returned can be set by calling Fill on the passed task. // // TODO: what is a good contract for receiving and passing errors and abort. // // If for a returned error x errors.Is(x, ErrAbort), all dependant tasks // will not be run, without this being an error. Run(t *Task, err error) error }
// A RunnerFunc runs a Task. type RunnerFunc func(t *Task)error func(f RunnerFunc)Run(t *Task, err error)error { return f(t) }