Documentation ¶
Overview ¶
Package viperKit
支持的配置文件格式(详见viper.go): "yaml", "yml", "json", "toml", "hcl", "tfvars", "dotenv", "env", "properties", "props", "prop", "ini"
Index ¶
- func GetContentType(path string) string
- func IsContentTypeSupported(contentType string) bool
- func MarshalToFile(obj interface{}, target string) errordeprecated
- func PolyfillContentType(contentType string) string
- func Read(data []byte, configType string, defaultMap map[string]interface{}) (*viper.Viper, error)
- func ReadFile(filePath string, defaultMap map[string]interface{}) (*viper.Viper, error)
- func Unmarshal(content []byte, configType string, defaultMap map[string]interface{}, ...) (*viper.Viper, error)
- func UnmarshalFromData(data *Data, defaultMap map[string]interface{}, ptr interface{}) (*viper.Viper, error)
- func UnmarshalFromFile(filePath string, defaultMap map[string]interface{}, ptr interface{}) (*viper.Viper, error)deprecated
- func UnmarshalProperties(content []byte, ptr interface{}) error
- type Data
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetContentType ¶
func IsContentTypeSupported ¶
IsContentTypeSupported
@param extName "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"
func MarshalToFile
deprecated
func PolyfillContentType ¶
PolyfillContentType
e.g.
extname := ".JSON" fmt.Println(viperKit.PolyfillContentType(extname)) // "json"
@param extName "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"
func Unmarshal ¶
func Unmarshal(content []byte, configType string, defaultMap map[string]interface{}, ptr interface{}) (*viper.Viper, error)
Unmarshal 读取配置文本内容,并反序列化.
@param configType 配置文件的类型(不区分大小写,详见viper.go):"yaml", "yml", "json", "toml", "hcl", "tfvars", "dotenv", "env", "properties", "props", "prop", "ini" @param defaultMap 默认值,可以为nil @param ptr 指针,且不能为nil
func UnmarshalFromData ¶
func UnmarshalFromFile
deprecated
func UnmarshalFromFile(filePath string, defaultMap map[string]interface{}, ptr interface{}) (*viper.Viper, error)
UnmarshalFromFile 读取配置文件,并反序列化.
Deprecated: 反序列化.yaml文件,先用 yamlKit.UnmarshalFromFile 替换 viperKit.UnmarshalFromFile,原因: https://github.com/spf13/viper/issues/1769
PS: (1) 配置文件 和 defaultMap 中,key首字母的大小写无所谓,都支持; (2) 支持配置文件的格式:JSON, TOML, HCL, .env, .yaml, .properties.
@param filePath 配置文件的路径(绝对路径 和 相对路径 都支持),内部会判断文件是否存在 @param defaultMap (可以为nil) 默认值;key如果有多层的话,用"."分隔,e.g. "WoService.LowerLimit" @param ptr (不能为nil) 指针
func UnmarshalProperties ¶ added in v3.0.15
UnmarshalProperties Deprecated: 反序列化后,key中的大写字母会被转换为小写字母.