-
Originally opened by @joscha-alisch in cuelang/cue#710 Say, I have a cue file like this test: fromGo.value I want to inject a struct from go into this file: struct FromGo {
Value: string
}
...
fromGo := FromGo{Value: "something"} So that the the cue file evaluates to test: "something" If I create another cue file that acts a a schema for the struct, load both files and b := &build.Instance{}
err := b.AddFile("test.cue", "test: fromGo.value")
panicErr(err)
err = b.AddFile("schema.cue", "fromGo: { value: string }")
panicErr(err)
r := cue.Runtime{}
i, err := r.Build(b)
panicErr(err)
fromGo := FromGo{Value: "something"}
i, err = i.Fill(&fromGo, "fromGo")
panicErr(err)
s, err := i.Lookup("test").String()
panicErr(err)
println(s) // prints "something" But I wonder whether there is a way to skip having to handcraft this second schema file? I.e. replace |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Original reply by @mpvl in cuelang/cue#710 (comment) The API could be improved. But from gocodec you can get a cue.Value, which has a Syntax method to get an AST, from which you can get a File using astutil.ToFile. |
Beta Was this translation helpful? Give feedback.
Original reply by @mpvl in cuelang/cue#710 (comment)
The API could be improved. But from gocodec you can get a cue.Value, which has a Syntax method to get an AST, from which you can get a File using astutil.ToFile.