-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (46 loc) · 1.35 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package carto
import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsimple"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
)
type Config struct {
Concurrency int `hcl:"concurrency,optional"`
Outputs []*OutputConfigBlock `hcl:"output,block"`
Layers []*LayerConfigBlock `hcl:"layer,block"`
Maps []*MapConfigBlock `hcl:"map,block"`
}
type OutputConfigBlock struct {
Name string `hcl:"name,label"`
Path string `hcl:"path"`
IncludeStatic bool `hcl:"include_static,optional"`
}
type LayerConfigBlock struct {
Name string `hcl:"name,label"`
Render string `hcl:"render"`
Opacity float64 `hcl:"opacity,optional"`
Options map[string]string `hcl:"options,optional"`
}
type MapConfigBlock struct {
Name string `hcl:"name,label"`
Output string `hcl:"output"`
Path string `hcl:"path"`
Layers []string `hcl:"layers"`
Version string `hcl:"version,optional"`
}
func newHCLEvalContext() *hcl.EvalContext {
return &hcl.EvalContext{
Variables: map[string]cty.Value{},
Functions: map[string]function.Function{},
}
}
func LoadConfig(path string) (*Config, error) {
var cfg Config
evalCtx := newHCLEvalContext()
err := hclsimple.DecodeFile(path, evalCtx, &cfg)
if err != nil {
return nil, err
}
return &cfg, nil
}