当我使用Unmarshalviper 的方法用 yaml 文件中的值填充我的配置结构时,一些结构字段变成了空!我这样做:
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 ...
我的结构是这样的:
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 文件中打印正确的值并且不为空!
SMILET
当为解决某一问题而选择数据结构时,应从哪些方面考虑?在编辑管理通讯录时,什么样的数据结构合适?
我这样理解 块级别标签结构标签用id id里面包含的内容用class
是不是可以考虑使用结构体来构造简单的数据模型?
为什我在中输入标签时不显示color标签
相关分类