-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
46 lines (37 loc) · 976 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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Kernel string `yaml:"kernel,omitempty"`
UbuntuVersion string `yaml:"ubuntuVersion,omitempty"`
Login string `yaml:"login,omitempty"`
Packages []string `yaml:"packages,omitempty"`
Systemd Systemd `yaml:"systemd,omitempty"`
Files []File `yaml:"files,omitempty"`
}
type Systemd struct {
Units []SystemdUnit `yaml:"units,omitempty"`
}
type SystemdUnit struct {
Name string `yaml:"name,omitempty"`
Enabled bool `yaml:"enabled,omitempty"`
}
type File struct {
Path string `yaml:"path,omitempty"`
Mode string `yaml:"mode,omitempty"`
Content string `yaml:"content,omitempty"`
}
func getConfigFromFile(file string) (*Config, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal([]byte(data), &config)
if err != nil {
return nil, err
}
return &config, nil
}