-
Notifications
You must be signed in to change notification settings - Fork 66
/
config.go
57 lines (51 loc) · 875 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
// Copyright 2015 The Loadcat Authors. All rights reserved.
package cfg
import (
"os"
"github.com/naoina/toml"
)
var Current = struct {
Core struct {
Address string
Dir string
Driver string
}
Nginx struct {
Mode string
Systemd struct {
Service string
}
}
}{}
func LoadFile(name string) error {
f, err := os.Open(name)
if os.IsNotExist(err) {
f, err = os.Create(name)
if err != nil {
return err
}
err = toml.NewEncoder(f).Encode(Current)
if err != nil {
return err
}
err = f.Close()
if err != nil {
return err
}
return nil
}
if err != nil {
return err
}
err = toml.NewDecoder(f).Decode(&Current)
if err != nil {
return err
}
return nil
}
func init() {
Current.Core.Address = ":26590"
Current.Core.Driver = "nginx"
Current.Nginx.Mode = "systemd"
Current.Nginx.Systemd.Service = "nginx.service"
}