mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
27 lines
515 B
Go
27 lines
515 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
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()
|
|
}
|