modify config

This commit is contained in:
rogee
2023-05-11 16:38:03 +00:00
parent c5d32dd2c3
commit ed2c7a8b98
5 changed files with 40 additions and 16 deletions

View File

@@ -5,14 +5,22 @@ import (
"github.com/spf13/viper"
)
func Load(file string) (*viper.Viper, error) {
func Load(file, app string) (*viper.Viper, error) {
v := viper.NewWithOptions(viper.KeyDelimiter("_"))
v.AutomaticEnv()
v.SetConfigFile(file)
if file == "" {
v.SetConfigType("toml")
v.SetConfigName(app)
v.AddConfigPath("/etc")
v.AddConfigPath("/usr/local/etc")
} else {
v.SetConfigFile(file)
}
if err := v.ReadInConfig(); err != nil {
return nil, err
}
err := container.Container.Provide(func() (*viper.Viper, error) {
return v, nil
})