28 lines
450 B
Go
28 lines
450 B
Go
package viper
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
"httppp/common"
|
|
"httppp/global"
|
|
)
|
|
|
|
func InitViper() {
|
|
v := viper.New()
|
|
v.SetConfigFile("config.yaml")
|
|
v.SetConfigType("yaml")
|
|
|
|
err := v.ReadInConfig()
|
|
if err != nil {
|
|
panic(fmt.Errorf("读取配置文件失败: %s", err))
|
|
}
|
|
|
|
config := &common.Config{}
|
|
err = v.Unmarshal(config)
|
|
if err != nil {
|
|
panic(fmt.Errorf("解析配置文件失败: %s", err))
|
|
}
|
|
|
|
global.Conf = config
|
|
}
|