coai/utils/config.go
2023-12-24 18:25:26 +08:00

29 lines
582 B
Go

package utils
import (
"fmt"
"github.com/spf13/viper"
"strings"
)
var configFile = "config.yaml"
var configExampleFile = "config.example.yaml"
func ReadConf() {
viper.SetConfigFile(configFile)
if !IsFileExist(configFile) {
fmt.Println(fmt.Sprintf("[service] config.yaml not found, creating one from template: %s", configExampleFile))
if err := CopyFile(configExampleFile, configFile); err != nil {
fmt.Println(err)
}
}
if err := viper.ReadInConfig(); err != nil {
panic(err)
}
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
}