1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00
gron/config.go

51 lines
995 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/creasty/defaults"
)
var config Config
type Config struct {
2022-03-28 19:55:21 +05:00
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"`
2022-06-21 22:14:50 +05:00
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
}