nunu-layout-admin/pkg/config/config.go

27 lines
415 B
Go
Raw Normal View History

2025-03-24 05:55:56 +00:00
package config
import (
"fmt"
"github.com/spf13/viper"
"os"
)
func NewConfig(p string) *viper.Viper {
envConf := os.Getenv("APP_CONF")
if envConf == "" {
envConf = p
}
fmt.Println("load conf file:", envConf)
return getConfig(envConf)
}
func getConfig(path string) *viper.Viper {
conf := viper.New()
conf.SetConfigFile(path)
err := conf.ReadInConfig()
if err != nil {
panic(err)
}
return conf
}