diff options
author | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 15:59:15 +0200 |
---|---|---|
committer | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 16:39:21 +0200 |
commit | 863486a6b71ed0e562a3965bed56465d007b1418 (patch) | |
tree | e93f6a687695af86d54237ec9f575d4ef104222d /vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go | |
parent | 49c1c7b4dc69ffb9ab52330e6dc52ccdd6351087 (diff) | |
download | terraform-provider-statuscake-add_contact_groups.tar.gz terraform-provider-statuscake-add_contact_groups.tar.zst terraform-provider-statuscake-add_contact_groups.zip |
update vendor and go.modadd_contact_groups
Diffstat (limited to 'vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go b/vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go new file mode 100644 index 0000000..b91141c --- /dev/null +++ b/vendor/github.com/zclconf/go-cty-yaml/cty_funcs.go | |||
@@ -0,0 +1,57 @@ | |||
1 | package yaml | ||
2 | |||
3 | import ( | ||
4 | "github.com/zclconf/go-cty/cty" | ||
5 | "github.com/zclconf/go-cty/cty/function" | ||
6 | ) | ||
7 | |||
8 | // YAMLDecodeFunc is a cty function for decoding arbitrary YAML source code | ||
9 | // into a cty Value, using the ImpliedType and Unmarshal methods of the | ||
10 | // Standard pre-defined converter. | ||
11 | var YAMLDecodeFunc = function.New(&function.Spec{ | ||
12 | Params: []function.Parameter{ | ||
13 | { | ||
14 | Name: "src", | ||
15 | Type: cty.String, | ||
16 | }, | ||
17 | }, | ||
18 | Type: func(args []cty.Value) (cty.Type, error) { | ||
19 | if !args[0].IsKnown() { | ||
20 | return cty.DynamicPseudoType, nil | ||
21 | } | ||
22 | if args[0].IsNull() { | ||
23 | return cty.NilType, function.NewArgErrorf(0, "YAML source code cannot be null") | ||
24 | } | ||
25 | return Standard.ImpliedType([]byte(args[0].AsString())) | ||
26 | }, | ||
27 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | ||
28 | if retType == cty.DynamicPseudoType { | ||
29 | return cty.DynamicVal, nil | ||
30 | } | ||
31 | return Standard.Unmarshal([]byte(args[0].AsString()), retType) | ||
32 | }, | ||
33 | }) | ||
34 | |||
35 | // YAMLEncodeFunc is a cty function for encoding an arbitrary cty value | ||
36 | // into YAML. | ||
37 | var YAMLEncodeFunc = function.New(&function.Spec{ | ||
38 | Params: []function.Parameter{ | ||
39 | { | ||
40 | Name: "value", | ||
41 | Type: cty.DynamicPseudoType, | ||
42 | AllowNull: true, | ||
43 | AllowDynamicType: true, | ||
44 | }, | ||
45 | }, | ||
46 | Type: function.StaticReturnType(cty.String), | ||
47 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | ||
48 | if !args[0].IsWhollyKnown() { | ||
49 | return cty.UnknownVal(retType), nil | ||
50 | } | ||
51 | raw, err := Standard.Marshal(args[0]) | ||
52 | if err != nil { | ||
53 | return cty.NilVal, err | ||
54 | } | ||
55 | return cty.StringVal(string(raw)), nil | ||
56 | }, | ||
57 | }) | ||