diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/go-ini/ini/struct.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/go-ini/ini/struct.go')
-rw-r--r-- | vendor/github.com/go-ini/ini/struct.go | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/vendor/github.com/go-ini/ini/struct.go b/vendor/github.com/go-ini/ini/struct.go index 5ef38d8..509c682 100644 --- a/vendor/github.com/go-ini/ini/struct.go +++ b/vendor/github.com/go-ini/ini/struct.go | |||
@@ -78,8 +78,14 @@ func parseDelim(actual string) string { | |||
78 | var reflectTime = reflect.TypeOf(time.Now()).Kind() | 78 | var reflectTime = reflect.TypeOf(time.Now()).Kind() |
79 | 79 | ||
80 | // setSliceWithProperType sets proper values to slice based on its type. | 80 | // setSliceWithProperType sets proper values to slice based on its type. |
81 | func setSliceWithProperType(key *Key, field reflect.Value, delim string) error { | 81 | func setSliceWithProperType(key *Key, field reflect.Value, delim string, allowShadow bool) error { |
82 | strs := key.Strings(delim) | 82 | var strs []string |
83 | if allowShadow { | ||
84 | strs = key.StringsWithShadows(delim) | ||
85 | } else { | ||
86 | strs = key.Strings(delim) | ||
87 | } | ||
88 | |||
83 | numVals := len(strs) | 89 | numVals := len(strs) |
84 | if numVals == 0 { | 90 | if numVals == 0 { |
85 | return nil | 91 | return nil |
@@ -92,9 +98,9 @@ func setSliceWithProperType(key *Key, field reflect.Value, delim string) error { | |||
92 | case reflect.String: | 98 | case reflect.String: |
93 | vals = strs | 99 | vals = strs |
94 | case reflect.Int: | 100 | case reflect.Int: |
95 | vals = key.Ints(delim) | 101 | vals, _ = key.parseInts(strs, true, false) |
96 | case reflect.Int64: | 102 | case reflect.Int64: |
97 | vals = key.Int64s(delim) | 103 | vals, _ = key.parseInt64s(strs, true, false) |
98 | case reflect.Uint: | 104 | case reflect.Uint: |
99 | vals = key.Uints(delim) | 105 | vals = key.Uints(delim) |
100 | case reflect.Uint64: | 106 | case reflect.Uint64: |
@@ -133,7 +139,7 @@ func setSliceWithProperType(key *Key, field reflect.Value, delim string) error { | |||
133 | // setWithProperType sets proper value to field based on its type, | 139 | // setWithProperType sets proper value to field based on its type, |
134 | // but it does not return error for failing parsing, | 140 | // but it does not return error for failing parsing, |
135 | // because we want to use default value that is already assigned to strcut. | 141 | // because we want to use default value that is already assigned to strcut. |
136 | func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string) error { | 142 | func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow bool) error { |
137 | switch t.Kind() { | 143 | switch t.Kind() { |
138 | case reflect.String: | 144 | case reflect.String: |
139 | if len(key.String()) == 0 { | 145 | if len(key.String()) == 0 { |
@@ -187,13 +193,25 @@ func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim stri | |||
187 | } | 193 | } |
188 | field.Set(reflect.ValueOf(timeVal)) | 194 | field.Set(reflect.ValueOf(timeVal)) |
189 | case reflect.Slice: | 195 | case reflect.Slice: |
190 | return setSliceWithProperType(key, field, delim) | 196 | return setSliceWithProperType(key, field, delim, allowShadow) |
191 | default: | 197 | default: |
192 | return fmt.Errorf("unsupported type '%s'", t) | 198 | return fmt.Errorf("unsupported type '%s'", t) |
193 | } | 199 | } |
194 | return nil | 200 | return nil |
195 | } | 201 | } |
196 | 202 | ||
203 | func parseTagOptions(tag string) (rawName string, omitEmpty bool, allowShadow bool) { | ||
204 | opts := strings.SplitN(tag, ",", 3) | ||
205 | rawName = opts[0] | ||
206 | if len(opts) > 1 { | ||
207 | omitEmpty = opts[1] == "omitempty" | ||
208 | } | ||
209 | if len(opts) > 2 { | ||
210 | allowShadow = opts[2] == "allowshadow" | ||
211 | } | ||
212 | return rawName, omitEmpty, allowShadow | ||
213 | } | ||
214 | |||
197 | func (s *Section) mapTo(val reflect.Value) error { | 215 | func (s *Section) mapTo(val reflect.Value) error { |
198 | if val.Kind() == reflect.Ptr { | 216 | if val.Kind() == reflect.Ptr { |
199 | val = val.Elem() | 217 | val = val.Elem() |
@@ -209,8 +227,8 @@ func (s *Section) mapTo(val reflect.Value) error { | |||
209 | continue | 227 | continue |
210 | } | 228 | } |
211 | 229 | ||
212 | opts := strings.SplitN(tag, ",", 2) // strip off possible omitempty | 230 | rawName, _, allowShadow := parseTagOptions(tag) |
213 | fieldName := s.parseFieldName(tpField.Name, opts[0]) | 231 | fieldName := s.parseFieldName(tpField.Name, rawName) |
214 | if len(fieldName) == 0 || !field.CanSet() { | 232 | if len(fieldName) == 0 || !field.CanSet() { |
215 | continue | 233 | continue |
216 | } | 234 | } |
@@ -231,7 +249,8 @@ func (s *Section) mapTo(val reflect.Value) error { | |||
231 | } | 249 | } |
232 | 250 | ||
233 | if key, err := s.GetKey(fieldName); err == nil { | 251 | if key, err := s.GetKey(fieldName); err == nil { |
234 | if err = setWithProperType(tpField.Type, key, field, parseDelim(tpField.Tag.Get("delim"))); err != nil { | 252 | delim := parseDelim(tpField.Tag.Get("delim")) |
253 | if err = setWithProperType(tpField.Type, key, field, delim, allowShadow); err != nil { | ||
235 | return fmt.Errorf("error mapping field(%s): %v", fieldName, err) | 254 | return fmt.Errorf("error mapping field(%s): %v", fieldName, err) |
236 | } | 255 | } |
237 | } | 256 | } |