diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go b/vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go new file mode 100644 index 0000000..67be1df --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/helper/hilmapstructure/hilmapstructure.go | |||
@@ -0,0 +1,41 @@ | |||
1 | package hilmapstructure | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "reflect" | ||
6 | |||
7 | "github.com/mitchellh/mapstructure" | ||
8 | ) | ||
9 | |||
10 | var hilMapstructureDecodeHookEmptySlice []interface{} | ||
11 | var hilMapstructureDecodeHookStringSlice []string | ||
12 | var hilMapstructureDecodeHookEmptyMap map[string]interface{} | ||
13 | |||
14 | // WeakDecode behaves in the same way as mapstructure.WeakDecode but has a | ||
15 | // DecodeHook which defeats the backward compatibility mode of mapstructure | ||
16 | // which WeakDecodes []interface{}{} into an empty map[string]interface{}. This | ||
17 | // allows us to use WeakDecode (desirable), but not fail on empty lists. | ||
18 | func WeakDecode(m interface{}, rawVal interface{}) error { | ||
19 | config := &mapstructure.DecoderConfig{ | ||
20 | DecodeHook: func(source reflect.Type, target reflect.Type, val interface{}) (interface{}, error) { | ||
21 | sliceType := reflect.TypeOf(hilMapstructureDecodeHookEmptySlice) | ||
22 | stringSliceType := reflect.TypeOf(hilMapstructureDecodeHookStringSlice) | ||
23 | mapType := reflect.TypeOf(hilMapstructureDecodeHookEmptyMap) | ||
24 | |||
25 | if (source == sliceType || source == stringSliceType) && target == mapType { | ||
26 | return nil, fmt.Errorf("Cannot convert a []interface{} into a map[string]interface{}") | ||
27 | } | ||
28 | |||
29 | return val, nil | ||
30 | }, | ||
31 | WeaklyTypedInput: true, | ||
32 | Result: rawVal, | ||
33 | } | ||
34 | |||
35 | decoder, err := mapstructure.NewDecoder(config) | ||
36 | if err != nil { | ||
37 | return err | ||
38 | } | ||
39 | |||
40 | return decoder.Decode(m) | ||
41 | } | ||