Documentation
¶
Overview ¶
Package dgocty contains the two function necessary to convert a dgo.Value into a cty.Value and vice versa.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromCty ¶
FromCty converts a cty.Value into its corresponding dgo.Value
Example (Mixed) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgocty"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/gocty"
)
func main() {
v, err := gocty.ToCtyValue(map[string]interface{}{"a": 1, "b": []interface{}{"c", 3.14, true}},
cty.Object(map[string]cty.Type{"a": cty.Number, "b": cty.Tuple([]cty.Type{cty.String, cty.Number, cty.Bool})}))
if err != nil {
fmt.Println(err)
} else {
fmt.Println(dgocty.FromCty(v))
}
}
Output: {"a":1.0,"b":{"c",3.14,true}}
func ToCty ¶
ToCty converts a dgo.Value into its corresponding cty.Value. dgo.Types that are not recognized will be converted to cty.Capsule values. dgo.Sensitive values will be unwrapped.
If attemptExplicit is true, then a cty.ListVal will be used instead of a cty.TupleVal and a cty.MapVal will be used instead of a cty.ObjectVal in cases when all values are of the same cty.Type.
Example (AutoObject) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Map("a", 1, "b", `two`)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
}
Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.StringVal("two")})
Example (AutoTuple) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Values("a", 2)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
}
Output: cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.NumberIntVal(2)})
Example (ForcedObject) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Map("a", 1, "b", 2)
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
}
Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.NumberIntVal(2)})
Example (ForcedTuple) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Strings("a", "b")
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
}
Output: cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.StringVal("b")})
Example (List) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Strings("a", "b")
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
}
Output: cty.ListVal([]cty.Value{cty.StringVal("a"), cty.StringVal("b")})
Example (Map) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Map("a", 1, "b", 2)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
}
Output: cty.MapVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.NumberIntVal(2)})
Example (Mixed) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
v := vf.Map("a", 1, "b", vf.Values("c", 3.14, true))
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
}
Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.TupleVal([]cty.Value{cty.StringVal("c"), cty.NumberFloatVal(3.14), cty.True})})
Example (Nil) ¶
package main
import (
"fmt"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func main() {
fmt.Println(dgocty.ToCty(vf.Nil, false).GoString())
}
Output: cty.NullVal(cty.DynamicPseudoType)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.