diff options
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/types_to_register.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/types_to_register.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/types_to_register.go b/vendor/github.com/zclconf/go-cty/cty/types_to_register.go new file mode 100644 index 0000000..e1e220a --- /dev/null +++ b/vendor/github.com/zclconf/go-cty/cty/types_to_register.go | |||
@@ -0,0 +1,57 @@ | |||
1 | package cty | ||
2 | |||
3 | import ( | ||
4 | "encoding/gob" | ||
5 | "fmt" | ||
6 | "math/big" | ||
7 | "strings" | ||
8 | |||
9 | "github.com/zclconf/go-cty/cty/set" | ||
10 | ) | ||
11 | |||
12 | // InternalTypesToRegister is a slice of values that covers all of the | ||
13 | // internal types used in the representation of cty.Type and cty.Value | ||
14 | // across all cty Types. | ||
15 | // | ||
16 | // This is intended to be used to register these types with encoding | ||
17 | // packages that require registration of types used in interfaces, such as | ||
18 | // encoding/gob, thus allowing cty types and values to be included in streams | ||
19 | // created from those packages. However, registering with gob is not necessary | ||
20 | // since that is done automatically as a side-effect of importing this package. | ||
21 | // | ||
22 | // Callers should not do anything with the values here except pass them on | ||
23 | // verbatim to a registration function. | ||
24 | // | ||
25 | // If the calling application uses Capsule types that wrap local structs either | ||
26 | // directly or indirectly, these structs may also need to be registered in | ||
27 | // order to support encoding and decoding of values of these types. That is the | ||
28 | // responsibility of the calling application. | ||
29 | var InternalTypesToRegister []interface{} | ||
30 | |||
31 | func init() { | ||
32 | InternalTypesToRegister = []interface{}{ | ||
33 | primitiveType{}, | ||
34 | typeList{}, | ||
35 | typeMap{}, | ||
36 | typeObject{}, | ||
37 | typeSet{}, | ||
38 | setRules{}, | ||
39 | set.Set{}, | ||
40 | typeTuple{}, | ||
41 | big.Float{}, | ||
42 | capsuleType{}, | ||
43 | []interface{}(nil), | ||
44 | map[string]interface{}(nil), | ||
45 | } | ||
46 | |||
47 | // Register these with gob here, rather than in gob.go, to ensure | ||
48 | // that this will always happen after we build the above. | ||
49 | for _, tv := range InternalTypesToRegister { | ||
50 | typeName := fmt.Sprintf("%T", tv) | ||
51 | if strings.HasPrefix(typeName, "cty.") { | ||
52 | gob.RegisterName(fmt.Sprintf("github.com/zclconf/go-cty/%s", typeName), tv) | ||
53 | } else { | ||
54 | gob.Register(tv) | ||
55 | } | ||
56 | } | ||
57 | } | ||