Redmage/cli/config.go

33 lines
710 B
Go
Raw Permalink Normal View History

2024-04-07 12:11:25 +07:00
package cli
import (
"github.com/adrg/xdg"
2024-04-08 16:59:42 +07:00
"github.com/joho/godotenv"
2024-04-07 12:11:25 +07:00
"github.com/tigorlazuardi/redmage/config"
"github.com/tigorlazuardi/redmage/pkg/log"
)
var cfg *config.Config
func initConfig() {
2024-04-08 16:59:42 +07:00
_ = godotenv.Load()
2024-04-07 12:11:25 +07:00
xdgJson, _ := xdg.ConfigFile("redmage/config.json")
xdgYaml, _ := xdg.ConfigFile("redmage/config.yaml")
cfg = config.NewConfigBuilder().
LoadDefault().
LoadJSONFile("/etc/redmage/config.json").
LoadYamlFile("/etc/redmage/config.yaml").
LoadJSONFile(xdgJson).
LoadYamlFile(xdgYaml).
LoadJSONFile("config.json").
LoadYamlFile("config.yaml").
LoadEnv().
LoadFlags(RootCmd.PersistentFlags()).
Build()
handler := log.NewHandler(cfg)
log.SetDefault(handler)
}