當我使用Unmarshalviper 的方法用 yaml 文件中的值填充我的配置結(jié)構(gòu)時,一些結(jié)構(gòu)字段變成了空!我這樣做:viper.SetConfigType("yaml")viper.SetConfigName("config")viper.AddConfigPath("/etc/myapp/")viper.AddConfigPath(".")err := viper.ReadInConfig()// error checking ...conf := &ConfYaml{}err = viper.Unmarshal(conf)// error checking ...我的結(jié)構(gòu)是這樣的:type ConfYaml struct { Endpoints SectionStorageEndpoint `yaml:"endpoints"`}type SectionStorageEndpoint struct { URL string `yaml:"url"` AccessKey string `yaml:"access_key"` SecretKey string `yaml:"secret_key"` UseSSL bool `yaml:"use_ssl"` Location string `yaml:"location"`}這里url和location字段在 yaml 文件中填充了正確的值,但其他字段為空!很想知道當我嘗試打印如下字段時:viper.Get("endpoints.access_key")它在 yaml 文件中打印正確的值并且不為空!
Viper 在解組時不考慮我的結(jié)構(gòu)中的 yaml 標簽
慕的地8271018
2023-06-26 17:34:20