You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`hclencoder` encodes/marshals/converts Go types into [HCL (Hashicorp Configuration Language)][HCL]. `hclencoder` ensures correctness in the generated HCL, and can be useful for creating programmatic, type-safe config files.
4
5
6
+
This fork is used for [multy](https://multy.dev) and addresses some of the problems we had - such as encoding expressions, escaping strings, and block lists. It uses hcl v2 api (hclwrite) rather than the old api by the original repo.
7
+
5
8
```go
6
9
package example
7
10
8
11
typeFarmstruct {
9
-
Namestring`hcl:"name"`
10
-
Ownedbool`hcl:"owned"`
11
-
Location []float64`hcl:"location"`
12
+
Namestring`hcl:"name"`
13
+
Ownedbool`hcl:"owned"`
14
+
Location []float64`hcl:"location"`
12
15
}
13
16
14
17
typeFarmerstruct {
15
-
Namestring`hcl:"name"`
16
-
Ageint`hcl:"age"`
17
-
SocialSecurityNumberstring`hcle:"omit"`
18
+
Namestring`hcl:"name,expr"`
19
+
Ageint`hcl:"age"`
20
+
SocialSecurityNumberstring`hcle:"omit"`
18
21
}
19
22
20
23
typeAnimalstruct {
21
-
Namestring`hcl:",key"`
22
-
Soundstring`hcl:"says" hcle:"omitempty"`
24
+
Namestring`hcl:",key"`
25
+
Soundstring`hcl:"says" hcle:"omitempty"`
26
+
}
27
+
28
+
typePetstruct {
29
+
Speciesstring`hcl:",key"`
30
+
Namestring`hcl:",key"`
31
+
Soundstring`hcl:"says" hcle:"omitempty"`
23
32
}
24
33
25
34
typeConfigstruct {
26
-
Farm`hcl:",squash"`
27
-
FarmerFarmer`hcl:"farmer"`
28
-
Animals []Animal`hcl:"animal"`
29
-
Buildingsmap[string]string`hcl:"buildings"`
35
+
Farm`hcl:",squash"`
36
+
FarmerFarmer`hcl:"farmer"`
37
+
Animals []Animal`hcl:"animal,blocks"`
38
+
Pets []Pet`hcl:"pet,blocks"`
39
+
Buildingsmap[string]string`hcl:"buildings"`
30
40
}
31
41
32
42
input:=Config{
@@ -36,7 +46,7 @@ input := Config{
36
46
Location: []float64{12.34, -5.67},
37
47
},
38
48
Farmer: Farmer{
39
-
Name: "Robert Beauregard-Michele McDonald, III",
49
+
Name: "var.name",
40
50
Age: 65,
41
51
SocialSecurityNumber: "please-dont-share-me",
42
52
},
@@ -52,6 +62,13 @@ input := Config{
52
62
{
53
63
Name: "rock",
54
64
},
65
+
},
66
+
Pets: []Pet{
67
+
{
68
+
Species: "cat",
69
+
Name: "whiskers",
70
+
Sound: "meow",
71
+
},
55
72
},
56
73
Buildings: map[string]string{
57
74
"House": "123 Numbers Lane",
@@ -71,7 +88,7 @@ fmt.Print(string(hcl))
71
88
//owned = true
72
89
//location = [12.34, -5.67]
73
90
//farmer {
74
-
// name = "Robert Beauregard-Michele McDonald, III"
0 commit comments