diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go b/vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go new file mode 100644 index 0000000..e563ee3 --- /dev/null +++ b/vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go | |||
@@ -0,0 +1,50 @@ | |||
1 | package convert | ||
2 | |||
3 | import ( | ||
4 | "math/big" | ||
5 | |||
6 | "github.com/zclconf/go-cty/cty" | ||
7 | ) | ||
8 | |||
9 | var stringTrue = cty.StringVal("true") | ||
10 | var stringFalse = cty.StringVal("false") | ||
11 | |||
12 | var primitiveConversionsSafe = map[cty.Type]map[cty.Type]conversion{ | ||
13 | cty.Number: { | ||
14 | cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) { | ||
15 | f := val.AsBigFloat() | ||
16 | return cty.StringVal(f.Text('f', -1)), nil | ||
17 | }, | ||
18 | }, | ||
19 | cty.Bool: { | ||
20 | cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) { | ||
21 | if val.True() { | ||
22 | return stringTrue, nil | ||
23 | } else { | ||
24 | return stringFalse, nil | ||
25 | } | ||
26 | }, | ||
27 | }, | ||
28 | } | ||
29 | |||
30 | var primitiveConversionsUnsafe = map[cty.Type]map[cty.Type]conversion{ | ||
31 | cty.String: { | ||
32 | cty.Number: func(val cty.Value, path cty.Path) (cty.Value, error) { | ||
33 | f, _, err := big.ParseFloat(val.AsString(), 10, 512, big.ToNearestEven) | ||
34 | if err != nil { | ||
35 | return cty.NilVal, path.NewErrorf("a number is required") | ||
36 | } | ||
37 | return cty.NumberVal(f), nil | ||
38 | }, | ||
39 | cty.Bool: func(val cty.Value, path cty.Path) (cty.Value, error) { | ||
40 | switch val.AsString() { | ||
41 | case "true", "1": | ||
42 | return cty.True, nil | ||
43 | case "false", "0": | ||
44 | return cty.False, nil | ||
45 | default: | ||
46 | return cty.NilVal, path.NewErrorf("a bool is required") | ||
47 | } | ||
48 | }, | ||
49 | }, | ||
50 | } | ||