forked from fluxcd/flux-recv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (32 loc) · 815 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
package main
import (
"fmt"
"io/ioutil"
"github.com/ghodss/yaml"
)
type Endpoint struct {
Source string `json:"source"`
KeyPath string `json:"keyPath"`
}
type Config struct {
FluxRecvVersion int `json:"fluxRecvVersion"`
API string `json:"api"`
Endpoints []Endpoint `json:"endpoints"`
}
func ConfigFromBytes(configBytes []byte) (Config, error) {
var config Config
if err := yaml.Unmarshal(configBytes, &config); err != nil {
return config, err
}
if config.FluxRecvVersion != 1 {
return config, fmt.Errorf("not a valid config file (field fluxRecvVersion != 1)")
}
return config, nil
}
func ConfigFromFile(path string) (Config, error) {
configBytes, err := ioutil.ReadFile(path)
if err != nil {
return Config{}, err
}
return ConfigFromBytes(configBytes)
}