]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | package gocty |
2 | ||
3 | import ( | |
4 | "math/big" | |
5 | "reflect" | |
6 | ||
7 | "github.com/zclconf/go-cty/cty" | |
8 | "github.com/zclconf/go-cty/cty/set" | |
9 | ) | |
10 | ||
11 | var valueType = reflect.TypeOf(cty.Value{}) | |
12 | var typeType = reflect.TypeOf(cty.Type{}) | |
13 | ||
14 | var setType = reflect.TypeOf(set.Set{}) | |
15 | ||
16 | var bigFloatType = reflect.TypeOf(big.Float{}) | |
17 | var bigIntType = reflect.TypeOf(big.Int{}) | |
18 | ||
19 | var emptyInterfaceType = reflect.TypeOf(interface{}(nil)) | |
20 | ||
21 | var stringType = reflect.TypeOf("") | |
22 | ||
23 | // structTagIndices interrogates the fields of the given type (which must | |
24 | // be a struct type, or we'll panic) and returns a map from the cty | |
25 | // attribute names declared via struct tags to the indices of the | |
26 | // fields holding those tags. | |
27 | // | |
28 | // This function will panic if two fields within the struct are tagged with | |
29 | // the same cty attribute name. | |
30 | func structTagIndices(st reflect.Type) map[string]int { | |
31 | ct := st.NumField() | |
32 | ret := make(map[string]int, ct) | |
33 | ||
34 | for i := 0; i < ct; i++ { | |
35 | field := st.Field(i) | |
36 | attrName := field.Tag.Get("cty") | |
37 | if attrName != "" { | |
38 | ret[attrName] = i | |
39 | } | |
40 | } | |
41 | ||
42 | return ret | |
43 | } |