diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/zclconf/go-cty/cty/path.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/path.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/path.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/path.go b/vendor/github.com/zclconf/go-cty/cty/path.go index 84a9de0..bf1a7c1 100644 --- a/vendor/github.com/zclconf/go-cty/cty/path.go +++ b/vendor/github.com/zclconf/go-cty/cty/path.go | |||
@@ -15,6 +15,10 @@ import ( | |||
15 | // but callers can also feel free to just produce a slice of PathStep manually | 15 | // but callers can also feel free to just produce a slice of PathStep manually |
16 | // and convert to this type, which may be more appropriate in environments | 16 | // and convert to this type, which may be more appropriate in environments |
17 | // where memory pressure is a concern. | 17 | // where memory pressure is a concern. |
18 | // | ||
19 | // Although a Path is technically mutable, by convention callers should not | ||
20 | // mutate a path once it has been built and passed to some other subsystem. | ||
21 | // Instead, use Copy and then mutate the copy before using it. | ||
18 | type Path []PathStep | 22 | type Path []PathStep |
19 | 23 | ||
20 | // PathStep represents a single step down into a data structure, as part | 24 | // PathStep represents a single step down into a data structure, as part |
@@ -47,6 +51,11 @@ func (p Path) Index(v Value) Path { | |||
47 | return ret | 51 | return ret |
48 | } | 52 | } |
49 | 53 | ||
54 | // IndexPath is a convenience method to start a new Path with an IndexStep. | ||
55 | func IndexPath(v Value) Path { | ||
56 | return Path{}.Index(v) | ||
57 | } | ||
58 | |||
50 | // GetAttr returns a new Path that is the reciever with a GetAttrStep appended | 59 | // GetAttr returns a new Path that is the reciever with a GetAttrStep appended |
51 | // to the end. | 60 | // to the end. |
52 | // | 61 | // |
@@ -62,6 +71,11 @@ func (p Path) GetAttr(name string) Path { | |||
62 | return ret | 71 | return ret |
63 | } | 72 | } |
64 | 73 | ||
74 | // GetAttrPath is a convenience method to start a new Path with a GetAttrStep. | ||
75 | func GetAttrPath(name string) Path { | ||
76 | return Path{}.GetAttr(name) | ||
77 | } | ||
78 | |||
65 | // Apply applies each of the steps in turn to successive values starting with | 79 | // Apply applies each of the steps in turn to successive values starting with |
66 | // the given value, and returns the result. If any step returns an error, | 80 | // the given value, and returns the result. If any step returns an error, |
67 | // the whole operation returns an error. | 81 | // the whole operation returns an error. |
@@ -132,9 +146,13 @@ type IndexStep struct { | |||
132 | // Apply returns the value resulting from indexing the given value with | 146 | // Apply returns the value resulting from indexing the given value with |
133 | // our key value. | 147 | // our key value. |
134 | func (s IndexStep) Apply(val Value) (Value, error) { | 148 | func (s IndexStep) Apply(val Value) (Value, error) { |
149 | if val == NilVal || val.IsNull() { | ||
150 | return NilVal, errors.New("cannot index a null value") | ||
151 | } | ||
152 | |||
135 | switch s.Key.Type() { | 153 | switch s.Key.Type() { |
136 | case Number: | 154 | case Number: |
137 | if !val.Type().IsListType() { | 155 | if !(val.Type().IsListType() || val.Type().IsTupleType()) { |
138 | return NilVal, errors.New("not a list type") | 156 | return NilVal, errors.New("not a list type") |
139 | } | 157 | } |
140 | case String: | 158 | case String: |
@@ -170,6 +188,10 @@ type GetAttrStep struct { | |||
170 | // Apply returns the value of our named attribute from the given value, which | 188 | // Apply returns the value of our named attribute from the given value, which |
171 | // must be of an object type that has a value of that name. | 189 | // must be of an object type that has a value of that name. |
172 | func (s GetAttrStep) Apply(val Value) (Value, error) { | 190 | func (s GetAttrStep) Apply(val Value) (Value, error) { |
191 | if val == NilVal || val.IsNull() { | ||
192 | return NilVal, errors.New("cannot access attributes on a null value") | ||
193 | } | ||
194 | |||
173 | if !val.Type().IsObjectType() { | 195 | if !val.Type().IsObjectType() { |
174 | return NilVal, errors.New("not an object type") | 196 | return NilVal, errors.New("not an object type") |
175 | } | 197 | } |