forked from krystal/guvnor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (38 loc) · 1002 Bytes
/
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
package guvnor
import (
"bytes"
"os"
"github.com/go-playground/validator/v10"
"github.com/krystal/guvnor/caddy"
"gopkg.in/yaml.v3"
)
type EngineConfig struct {
Caddy caddy.Config `yaml:"caddy"`
Paths PathsConfig `yaml:"paths"`
}
type PathsConfig struct {
// Config is the path to the directory containing service configs
Config string `yaml:"config" validate:"required"`
// State is the path to store state about deployments etc
State string `yaml:"state" validate:"required"`
}
func LoadConfig(validate *validator.Validate, pathOverride string) (*EngineConfig, error) {
path := "/etc/guvnor/config.yaml"
if pathOverride != "" {
path = pathOverride
}
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
decoder := yaml.NewDecoder(bytes.NewBuffer(data))
decoder.KnownFields(true)
cfg := &EngineConfig{}
if err := decoder.Decode(cfg); err != nil {
return nil, err
}
if err := validate.Struct(cfg); err != nil {
return nil, err
}
return cfg, nil
}