-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
59 lines (45 loc) · 855 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
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"io/ioutil"
"os"
"github.com/the-obsidian/mc/plugin"
"gopkg.in/yaml.v2"
)
type Config struct {
Plugins []*plugin.Plugin
unknownKeys []string
}
func NewConfigFromString(data string) (*Config, error) {
c := Config{}
err := yaml.Unmarshal([]byte(data), &c)
if err != nil {
return nil, err
}
for _, plugin := range c.Plugins {
err = plugin.Init()
if err != nil {
return nil, err
}
}
return &c, nil
}
func NewConfigFromFile(path string) (*Config, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return NewConfigFromString(string(data))
}
func (c *Config) InstallPlugins() error {
err := os.MkdirAll("plugins", 0755)
if err != nil {
return err
}
for _, plugin := range c.Plugins {
err = plugin.Install()
if err != nil {
return err
}
}
return nil
}