-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
40 lines (34 loc) · 978 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 utils
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/ghodss/yaml"
"github.com/platform9/nodeadm/apis"
)
func UseNumber(d *json.Decoder) *json.Decoder {
d.UseNumber()
return d
}
func InitConfigurationFromFile(path string) (*apis.InitConfiguration, error) {
f, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("unable to read config file: %v", err)
}
config := apis.InitConfiguration{}
if err := yaml.Unmarshal(f, &config, UseNumber); err != nil {
return nil, fmt.Errorf("unable to parse config file: %v", err)
}
return &config, nil
}
func JoinConfigurationFromFile(path string) (*apis.JoinConfiguration, error) {
f, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("unable to read config file: %v", err)
}
config := apis.JoinConfiguration{}
if err := yaml.Unmarshal(f, &config, UseNumber); err != nil {
return nil, fmt.Errorf("unable to parse config file: %v", err)
}
return &config, nil
}