Skip to content

Commit 607334f

Browse files
author
Paddy Carver
committed
Broke up types.go into different files.
Same content, different files, easier to navigate.
1 parent 5549dbf commit 607334f

File tree

9 files changed

+219
-208
lines changed

9 files changed

+219
-208
lines changed

tfprotov5/tftypes/list.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tftypes
2+
3+
type List struct {
4+
ElementType Type
5+
}
6+
7+
func (l List) Is(t Type) bool {
8+
_, ok := t.(List)
9+
return ok
10+
}
11+
12+
func (l List) String() string {
13+
return "tftypes.List"
14+
}
15+
16+
func (l List) private() {}

tfprotov5/tftypes/map.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tftypes
2+
3+
type Map struct {
4+
AttributeType Type
5+
}
6+
7+
func (m Map) Is(t Type) bool {
8+
_, ok := t.(Map)
9+
return ok
10+
}
11+
12+
func (m Map) String() string {
13+
return "tftypes.Map"
14+
}
15+
16+
func (m Map) private() {}

tfprotov5/tftypes/object.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tftypes
2+
3+
type Object struct {
4+
AttributeTypes map[string]Type
5+
}
6+
7+
func (o Object) Is(t Type) bool {
8+
_, ok := t.(Object)
9+
return ok
10+
}
11+
12+
func (o Object) String() string {
13+
return "tftypes.Object"
14+
}
15+
16+
func (o Object) private() {}

tfprotov5/tftypes/primitive.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tftypes
2+
3+
const (
4+
UnknownType = primitive("Unknown")
5+
DynamicPseudoType = primitive("DynamicPseudoType")
6+
String = primitive("String")
7+
Number = primitive("Number")
8+
Bool = primitive("Bool")
9+
)
10+
11+
var (
12+
_ Type = primitive("test")
13+
)
14+
15+
type primitive string
16+
17+
func (p primitive) Is(t Type) bool {
18+
v, ok := t.(primitive)
19+
if !ok {
20+
return false
21+
}
22+
return p == v
23+
}
24+
25+
func (p primitive) String() string {
26+
return "tftypes." + string(p)
27+
}
28+
29+
func (p primitive) private() {}

tfprotov5/tftypes/types.go renamed to tfprotov5/tftypes/raw_value.go

Lines changed: 0 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -7,118 +7,6 @@ import (
77
"math/big"
88
)
99

10-
type unknown byte
11-
12-
type Type interface {
13-
Is(Type) bool
14-
String() string
15-
private()
16-
}
17-
18-
type primitive string
19-
20-
func (p primitive) Is(t Type) bool {
21-
v, ok := t.(primitive)
22-
if !ok {
23-
return false
24-
}
25-
return p == v
26-
}
27-
28-
func (p primitive) String() string {
29-
return "tftypes." + string(p)
30-
}
31-
32-
func (p primitive) private() {}
33-
34-
const (
35-
UnknownValue = unknown(0)
36-
UnknownType = primitive("Unknown")
37-
DynamicPseudoType = primitive("DynamicPseudoType")
38-
String = primitive("String")
39-
Number = primitive("Number")
40-
Bool = primitive("Bool")
41-
)
42-
43-
var (
44-
_ Type = primitive("test")
45-
)
46-
47-
type List struct {
48-
ElementType Type
49-
}
50-
51-
func (l List) Is(t Type) bool {
52-
_, ok := t.(List)
53-
return ok
54-
}
55-
56-
func (l List) String() string {
57-
return "tftypes.List"
58-
}
59-
60-
func (l List) private() {}
61-
62-
type Set struct {
63-
ElementType Type
64-
}
65-
66-
func (s Set) Is(t Type) bool {
67-
_, ok := t.(Set)
68-
return ok
69-
}
70-
71-
func (s Set) String() string {
72-
return "tftypes.Set"
73-
}
74-
75-
func (s Set) private() {}
76-
77-
type Map struct {
78-
AttributeType Type
79-
}
80-
81-
func (m Map) Is(t Type) bool {
82-
_, ok := t.(Map)
83-
return ok
84-
}
85-
86-
func (m Map) String() string {
87-
return "tftypes.Map"
88-
}
89-
90-
func (m Map) private() {}
91-
92-
type Tuple struct {
93-
ElementTypes []Type
94-
}
95-
96-
func (tu Tuple) Is(t Type) bool {
97-
_, ok := t.(Tuple)
98-
return ok
99-
}
100-
101-
func (t Tuple) String() string {
102-
return "tftypes.Tuple"
103-
}
104-
105-
func (t Tuple) private() {}
106-
107-
type Object struct {
108-
AttributeTypes map[string]Type
109-
}
110-
111-
func (o Object) Is(t Type) bool {
112-
_, ok := t.(Object)
113-
return ok
114-
}
115-
116-
func (o Object) String() string {
117-
return "tftypes.Object"
118-
}
119-
120-
func (o Object) private() {}
121-
12210
type Unmarshaler interface {
12311
UnmarshalTerraform5Type(RawValue) error
12412
}
@@ -428,99 +316,3 @@ func rawValueFromComplexType(typ Type, val interface{}) (RawValue, error) {
428316
// TODO: return error
429317
return RawValue{}, nil
430318
}
431-
432-
func parseType(in interface{}) (Type, error) {
433-
switch v := in.(type) {
434-
// primitive types are represented just as strings,
435-
// with the type name in the string itself
436-
case string:
437-
switch v {
438-
case "string":
439-
return String, nil
440-
case "number":
441-
return Number, nil
442-
case "bool":
443-
return Bool, nil
444-
default:
445-
// TODO: return an error
446-
}
447-
case []interface{}:
448-
// sets, lists, tuples, maps, and objects are
449-
// represented as slices, recursive iterations of this
450-
// type/value syntax
451-
if len(v) < 1 {
452-
// TODO: return an error
453-
}
454-
switch v[0] {
455-
case "set":
456-
if len(v) != 2 {
457-
// TODO: return an error
458-
}
459-
subType, err := parseType(v[1])
460-
if err != nil {
461-
// TODO: return an error
462-
}
463-
return Set{
464-
ElementType: subType,
465-
}, nil
466-
case "list":
467-
if len(v) != 2 {
468-
// TODO: return an error
469-
}
470-
subType, err := parseType(v[1])
471-
if err != nil {
472-
// TODO: return an error
473-
}
474-
return List{
475-
ElementType: subType,
476-
}, nil
477-
case "tuple":
478-
if len(v) < 2 {
479-
// TODO: return an error
480-
}
481-
var types []Type
482-
for _, typ := range v {
483-
subType, err := parseType(typ)
484-
if err != nil {
485-
// TODO: return an error
486-
}
487-
types = append(types, subType)
488-
}
489-
return Tuple{
490-
ElementTypes: types,
491-
}, nil
492-
case "map":
493-
if len(v) != 2 {
494-
// TODO: return an error
495-
}
496-
subType, err := parseType(v[1])
497-
if err != nil {
498-
// TODO: return an error
499-
}
500-
return Map{
501-
AttributeType: subType,
502-
}, nil
503-
case "object":
504-
if len(v) < 2 {
505-
// TODO: return an error
506-
}
507-
types := map[string]Type{}
508-
valTypes := v[1].(map[string]interface{})
509-
for key, typ := range valTypes {
510-
subType, err := parseType(typ)
511-
if err != nil {
512-
// TODO: return an error
513-
}
514-
types[key] = subType
515-
}
516-
return Object{
517-
AttributeTypes: types,
518-
}, nil
519-
default:
520-
// TODO: return an error
521-
return nil, nil
522-
}
523-
}
524-
// TODO: return an error
525-
return nil, nil
526-
}

tfprotov5/tftypes/set.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tftypes
2+
3+
type Set struct {
4+
ElementType Type
5+
}
6+
7+
func (s Set) Is(t Type) bool {
8+
_, ok := t.(Set)
9+
return ok
10+
}
11+
12+
func (s Set) String() string {
13+
return "tftypes.Set"
14+
}
15+
16+
func (s Set) private() {}

tfprotov5/tftypes/tuple.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tftypes
2+
3+
type Tuple struct {
4+
ElementTypes []Type
5+
}
6+
7+
func (tu Tuple) Is(t Type) bool {
8+
_, ok := t.(Tuple)
9+
return ok
10+
}
11+
12+
func (t Tuple) String() string {
13+
return "tftypes.Tuple"
14+
}
15+
16+
func (t Tuple) private() {}

0 commit comments

Comments
 (0)