-
Notifications
You must be signed in to change notification settings - Fork 31
/
config.go
55 lines (48 loc) · 942 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
// goforever - processes management
// Copyright (c) 2013 Garrett Woodworth (https://github.com/gwoo).
package main
import (
"os"
"path/filepath"
"github.com/BurntSushi/toml"
)
type Config struct {
IP string
Port string
Username string
Password string
Daemonize bool
Pidfile Pidfile
Logfile string
Errfile string
Processes []*Process `toml:"process"`
}
func (c Config) Keys() []string {
keys := []string{}
for _, p := range c.Processes {
keys = append(keys, p.Name)
}
return keys
}
func (c Config) Get(key string) *Process {
for _, p := range c.Processes {
if p.Name == key {
return p
}
}
return nil
}
func LoadConfig(file string) (*Config, error) {
if string(file[0]) != "/" {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
file = filepath.Join(wd, file)
}
var c *Config
if _, err := toml.DecodeFile(file, &c); err != nil {
return nil, err
}
return c, nil
}