You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think what you are actually after is CompileString. At least I hope the following example makes the distinction between cue.Context.Encode and cue.Context.CompileString clear
go mod tidy
go run .
cmp stdout stdout.golden
-- go.mod --
module mod.example
go 1.22.3
require cuelang.org/go v0.9.0
-- main.go --
package main
import (
"fmt"
"cuelang.org/go/cue/cuecontext"
)
func main() {
ctx := cuecontext.New()
tmap := map[string]any{
"Ref": struct {
Val string
}{
Val: "test",
},
}
// Use cue.Context.Encode to convert a Go value to
// CUE data. Note that the Go value can contain
// cue.Value values.
tmapValue := ctx.Encode(tmap)
// Use cue.Context.CompileString to compile some CUE
derived := ctx.CompileString(`
Ref: _
x: "\(Ref.Val)/gg"
`)
// Use cue.Value.Unify to unify
res := tmapValue.Unify(derived)
fmt.Printf("%v\n", res)
}
-- stdout.golden --
{
Ref: {
Val: "test"
}
x: "test/gg"
}
If you use cue.Context.Encode on a Go value, then the resulting cue.Value will be just data
Hence your expectation of a reference ("(Ref.Val)") resolving is not correct.
But as you can see, you can use a combination of various techniques to give you a variety of cue.Value's, and "glue" them together using cue.Value.Unify
The text was updated successfully, but these errors were encountered:
Slack thread: https://cuelang.slack.com/archives/CLT3ULF6C/p1716865650006559
Thread content
OP
my expectation was that fill path would do unification .. i am starting to think that i am missing something about escaping that string but not sure.
Reply
I think what you are actually after is CompileString. At least I hope the following example makes the distinction between cue.Context.Encode and cue.Context.CompileString clear
If you use cue.Context.Encode on a Go value, then the resulting cue.Value will be just data
Hence your expectation of a reference ("(Ref.Val)") resolving is not correct.
But as you can see, you can use a combination of various techniques to give you a variety of cue.Value's, and "glue" them together using cue.Value.Unify
The text was updated successfully, but these errors were encountered: