| giolekva | b1f19ee | 2020-05-16 11:31:20 +0400 | [diff] [blame^] | 1 | package appmanager |
| 2 | |
| 3 | import ( |
| 4 | "io/ioutil" |
| 5 | "os" |
| 6 | |
| 7 | "gopkg.in/yaml.v2" |
| 8 | ) |
| 9 | |
| 10 | type Action struct { |
| 11 | Name string `yaml:"name"` |
| 12 | Template string `yaml:"template"` |
| 13 | } |
| 14 | |
| 15 | type Actions struct { |
| 16 | Actions []Action `yaml:"actions"` |
| 17 | } |
| 18 | |
| 19 | func FromYaml(str string, out interface{}) error { |
| 20 | return yaml.Unmarshal([]byte(str), out) |
| 21 | } |
| 22 | |
| 23 | func FromYamlFile(actionsFile string, out interface{}) error { |
| 24 | f, err := os.Open(actionsFile) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | defer f.Close() |
| 29 | b, err := ioutil.ReadAll(f) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | return FromYaml(string(b), out) |
| 34 | } |