Ini config file UnmarshalKey is empty #1442
Unanswered
LoveVsLike
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
package main
import (
"fmt"
"github.com/spf13/viper"
)
/**
[domains]
CrowdDomain = test
BasePortrait = test1
RealtimePortrait = test2
PortrayalVBU = test3
[cron]
DataJobCron = 0 1 * * * ?
JobCron = 0 5 * * * ?
*/
func main() {
conf := viper.New() //初始话一个viper.viper对象
conf.AddConfigPath("conf")
conf.SetConfigName("config")
conf.SetConfigType("ini")
if err := conf.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println("找不到配置文件")
} else {
fmt.Println("配置文件出错")
}
}
}
type Domains struct {
CrowdDomain string
mapstructure:",CrowdDomain"BasePortrait string
mapstructure:",BasePortrait"RealtimePortrait string
mapstructure:",RealtimePortrait"PortrayalVBU string
mapstructure:",PortrayalVBU"}
type ConfigStruct struct {
Domains Domains
mapstructure:"domains"}
Beta Was this translation helpful? Give feedback.
All reactions