]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/zclconf/go-cty/cty/convert/conversion_primitive.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / zclconf / go-cty / cty / convert / conversion_primitive.go
1 package convert
2
3 import (
4 "github.com/zclconf/go-cty/cty"
5 )
6
7 var stringTrue = cty.StringVal("true")
8 var stringFalse = cty.StringVal("false")
9
10 var primitiveConversionsSafe = map[cty.Type]map[cty.Type]conversion{
11 cty.Number: {
12 cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) {
13 f := val.AsBigFloat()
14 return cty.StringVal(f.Text('f', -1)), nil
15 },
16 },
17 cty.Bool: {
18 cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) {
19 if val.True() {
20 return stringTrue, nil
21 } else {
22 return stringFalse, nil
23 }
24 },
25 },
26 }
27
28 var primitiveConversionsUnsafe = map[cty.Type]map[cty.Type]conversion{
29 cty.String: {
30 cty.Number: func(val cty.Value, path cty.Path) (cty.Value, error) {
31 v, err := cty.ParseNumberVal(val.AsString())
32 if err != nil {
33 return cty.NilVal, path.NewErrorf("a number is required")
34 }
35 return v, nil
36 },
37 cty.Bool: func(val cty.Value, path cty.Path) (cty.Value, error) {
38 switch val.AsString() {
39 case "true", "1":
40 return cty.True, nil
41 case "false", "0":
42 return cty.False, nil
43 default:
44 return cty.NilVal, path.NewErrorf("a bool is required")
45 }
46 },
47 },
48 }