-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (39 loc) · 995 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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/creasty/defaults"
)
var config Config
type Config struct {
TimeFormat string `default:"02.01.2006 15:04"`
JobConfigsPath string `default:"gron.d"`
LogFilePath string `default:"gron.log"` // core log file path
LogFilesPath string `default:"logs"` // job log files path
HttpListenAddr string `default:"127.0.0.1:9876"`
HttpProxyAddr string // proxy address for local http client
}
func initConfig() error {
ex, err := os.Executable()
if err != nil {
return err
}
if len(os.Args) > 2 {
return fmt.Errorf("Usage: %s [path to config]", filepath.Base(ex))
}
configFilePath := filepath.Join(filepath.Dir(ex), defaultConfigFileName)
if len(os.Args) == 2 {
configFilePath = os.Args[1]
}
_, err = toml.DecodeFile(configFilePath, &config)
if err != nil {
return err
}
// Set defaults
if err := defaults.Set(&config); err != nil {
return err
}
return nil
}