✨ Load config from file with defaults
This commit is contained in:
parent
2da9fcac37
commit
40f9518611
8 changed files with 127 additions and 2 deletions
26
config/load.go
Normal file
26
config/load.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
fp "path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var ConfigPath string
|
||||
|
||||
func init() {
|
||||
conf, _ := os.UserConfigDir()
|
||||
ConfigPath = fp.Join(conf, "my-log", "config.toml")
|
||||
}
|
||||
|
||||
func Load() (Config, error) {
|
||||
c, _ := DefaultConfig()
|
||||
_, err := os.Stat(ConfigPath)
|
||||
if os.IsNotExist(err) {
|
||||
return c, nil
|
||||
}
|
||||
_, err = toml.DecodeFile(ConfigPath, &c)
|
||||
// @todo get environ
|
||||
return c, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue