-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
42 lines (33 loc) · 874 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
package main
import (
"io/ioutil"
"os"
"github.com/k0kubun/pp"
"github.com/pelletier/go-toml"
"go.uber.org/zap"
)
// Config is top level init configuration holder
type Config struct {
PreStart Command `toml:"pre_start, omitempty"`
PostStart Command `toml:"post_start, omitempty"`
Process []Command `toml:"process"`
Cron []Cron `toml:"cron"`
}
// NewConfig returns Config instance for provided file
func NewConfig(path string) *Config {
c := &Config{}
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Fatal("unable to open", zap.String("config", path), zap.Error(err))
}
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal("Config cannot be read", zap.Error(err))
}
if err = toml.Unmarshal(data, c); err != nil {
log.Fatal("Config cannot be parsed", zap.Error(err))
}
if showDebug {
pp.Println(c)
}
return c
}