Skip to content

Commit cb91e76

Browse files
Update README.md
1 parent 7e1533e commit cb91e76

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

readme.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
# hclencoder<br>[![Build Status](https://travis-ci.org/rodaine/hclencoder.svg?branch=master)](https://travis-ci.org/rodaine/hclencoder) [![GoDoc](https://godoc.org/github.com/rodaine/hclencoder?status.svg)](https://godoc.org/github.com/rodaine/hclencoder)
22

3+
34
`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.
45

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+
58
```go
69
package example
710

811
type Farm struct {
9-
Name string `hcl:"name"`
10-
Owned bool `hcl:"owned"`
11-
Location []float64 `hcl:"location"`
12+
Name string `hcl:"name"`
13+
Owned bool `hcl:"owned"`
14+
Location []float64 `hcl:"location"`
1215
}
1316

1417
type Farmer struct {
15-
Name string `hcl:"name"`
16-
Age int `hcl:"age"`
17-
SocialSecurityNumber string `hcle:"omit"`
18+
Name string `hcl:"name,expr"`
19+
Age int `hcl:"age"`
20+
SocialSecurityNumber string `hcle:"omit"`
1821
}
1922

2023
type Animal struct {
21-
Name string `hcl:",key"`
22-
Sound string `hcl:"says" hcle:"omitempty"`
24+
Name string `hcl:",key"`
25+
Sound string `hcl:"says" hcle:"omitempty"`
26+
}
27+
28+
type Pet struct {
29+
Species string `hcl:",key"`
30+
Name string `hcl:",key"`
31+
Sound string `hcl:"says" hcle:"omitempty"`
2332
}
2433

2534
type Config struct {
26-
Farm `hcl:",squash"`
27-
Farmer Farmer `hcl:"farmer"`
28-
Animals []Animal `hcl:"animal"`
29-
Buildings map[string]string `hcl:"buildings"`
35+
Farm `hcl:",squash"`
36+
Farmer Farmer `hcl:"farmer"`
37+
Animals []Animal `hcl:"animal,blocks"`
38+
Pets []Pet `hcl:"pet,blocks"`
39+
Buildings map[string]string `hcl:"buildings"`
3040
}
3141

3242
input := Config{
@@ -36,7 +46,7 @@ input := Config{
3646
Location: []float64{12.34, -5.67},
3747
},
3848
Farmer: Farmer{
39-
Name: "Robert Beauregard-Michele McDonald, III",
49+
Name: "var.name",
4050
Age: 65,
4151
SocialSecurityNumber: "please-dont-share-me",
4252
},
@@ -52,6 +62,13 @@ input := Config{
5262
{
5363
Name: "rock",
5464
},
65+
},
66+
Pets: []Pet{
67+
{
68+
Species: "cat",
69+
Name: "whiskers",
70+
Sound: "meow",
71+
},
5572
},
5673
Buildings: map[string]string{
5774
"House": "123 Numbers Lane",
@@ -71,7 +88,7 @@ fmt.Print(string(hcl))
7188
//owned = true
7289
//location = [12.34, -5.67]
7390
//farmer {
74-
// name = "Robert Beauregard-Michele McDonald, III"
91+
// name = var.name
7592
// age = 65
7693
//}
7794
//animal "cow" {

0 commit comments

Comments
 (0)