dgocty

package module
v0.0.0-...-f1aa31e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

dgocty (Dynamic Go <=> cty)

The cty type system defined in go-cty is used by Terraform to represent configurations and states. This module provides conversion routines to convert a dgo.Value into a cty.Value and vice versa.

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

func FromCty(cv cty.Value) dgo.Value

FromCty converts a cty.Value into its corresponding dgo.Value

Example (Mixed)
package main

import (
	"fmt"

	"github.com/lyraproj/dgo/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

func ToCty(v dgo.Value) cty.Value

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.

Example (List)
package main

import (
	"fmt"

	"github.com/lyraproj/dgo/dgocty"
	"github.com/lyraproj/dgo/vf"
)

func main() {
	v := vf.Strings("a", "b")
	c := dgocty.ToCty(v)
	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/dgocty"
	"github.com/lyraproj/dgo/vf"
)

func main() {
	v := vf.Map("a", 1, "b", 2)
	c := dgocty.ToCty(v)
	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/dgocty"
	"github.com/lyraproj/dgo/vf"
)

func main() {
	v := vf.Map("a", 1, "b", vf.Values("c", 3.14, true))
	c := dgocty.ToCty(v)
	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/dgocty"
	"github.com/lyraproj/dgo/vf"
)

func main() {
	fmt.Println(dgocty.ToCty(vf.Nil).GoString())
}
Output:

cty.NullVal(cty.DynamicPseudoType)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL