-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-yml-base.go
45 lines (34 loc) · 896 Bytes
/
service-yml-base.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
package service_yml
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)
type ServiceYml struct {
Services map[string]Service `yaml:"services,omitempty"`
Databases []string `yaml:"databases,omitempty"`
}
func (s *ServiceYml) UnmarshalFromFile(path string) error {
var err error
_, err = os.Stat(path)
CheckError(err)
yamlFile, err := ioutil.ReadFile(path)
serviceYml := ServiceYml{
Services: map[string]Service{},
Databases: make([]string, 1),
}
if err := yaml.Unmarshal([]byte(yamlFile), &serviceYml); err != nil {
fmt.Println(err.Error())
}
s.Services = serviceYml.Services
s.Databases = serviceYml.Databases
return nil
}
func (s ServiceYml) MarshalToFile(path string) error {
file, err := yaml.Marshal(s)
file = []byte("# Generated with <3 by Cloud66\n\n" + string(file))
err = ioutil.WriteFile(path, file, 0644)
CheckError(err)
return nil
}