/
primitive.go
56 lines (45 loc) · 1.16 KB
/
primitive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package tftypes
import "fmt"
const (
// DynamicPseudoType is a pseudo-type in Terraform's type system that
// is used as a wildcard type. It indicates that any Terraform type can
// be used.
DynamicPseudoType = primitive("DynamicPseudoType")
// String is a primitive type in Terraform that represents a UTF-8
// string of bytes.
String = primitive("String")
// Number is a primitive type in Terraform that represents a real
// number.
Number = primitive("Number")
// Bool is a primitive type in Terraform that represents a true or
// false boolean value.
Bool = primitive("Bool")
)
var (
_ Type = primitive("test")
)
type primitive string
func (p primitive) Is(t Type) bool {
v, ok := t.(primitive)
if !ok {
return false
}
return p == v
}
func (p primitive) String() string {
return "tftypes." + string(p)
}
func (p primitive) private() {}
func (p primitive) MarshalJSON() ([]byte, error) {
switch p {
case String:
return []byte(`"string"`), nil
case Number:
return []byte(`"number"`), nil
case Bool:
return []byte(`"bool"`), nil
case DynamicPseudoType:
return []byte(`"dynamic"`), nil
}
return nil, fmt.Errorf("unknown primitive type %q", p)
}