Load config from file with defaults

This commit is contained in:
Dan Jones 2024-02-04 18:19:19 -06:00
commit 40f9518611
8 changed files with 127 additions and 2 deletions

26
config/load.go Normal file
View 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
}