Documentation
¶
Index ¶
- func AnalyzeConfig(options *ConfigOptions, configTypes ...interface{}) (viper *viper.Viper)
- func InitConfigFromEnv(config *ConfigOptions)
- func MappingConfigToStruct(config *viper.Viper, configTypes ...interface{}) error
- func ReadFile(filePath, fileName, configType string) (config *viper.Viper, err error)
- func ReadIniConfig(filePath, fileName string) (*viper.Viper, error)
- func ReadJsonConfig(filePath, fileName string) (*viper.Viper, error)
- func ReadYamlConfig(filePath, fileName string) (*viper.Viper, error)
- type ConfigOptions
- type NacosConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeConfig ¶
func AnalyzeConfig(options *ConfigOptions, configTypes ...interface{}) (viper *viper.Viper)
AnalyzeConfig 解析配置文件,并将配置信息映射到传入的参数中
该方法需要再corbra解析完命令后再调用,这样就可以将命令行的参数映射到options里面 @Description: 该方法是先读取一个配置文件的设置,从中获取到真正业务的配置文件数据,然后再读取对应的配置文件的方式 整体配置文件的来源有三种方式: 从当前路径config.yaml文件中读取(默认)、从环境变量中读取、从命令行参数中读取 三种读取方式优先级依次上升 该方法支持从本地配置文件读取(ini,json,yaml文件)和从配置中心nacos中读取的方式,通过总配置的type字段区分 @param configTypes :需要映射的类型集合,这里要传入指针,否则无法映射成功 需要注意的是,如果配置对象有继承关系,需要将父类和子类分别传入,否则无法解析成功 @return 返回读取文件的viper对象,以供用户自由获取
func InitConfigFromEnv ¶
func InitConfigFromEnv(config *ConfigOptions)
InitConfigFromEnv 从环境变量中获取配置参数
func MappingConfigToStruct ¶
func ReadIniConfig ¶
ReadIniConfig 读取ini类型配置文件
func ReadJsonConfig ¶
ReadJsonConfig 读取json类型配置文件
Types ¶
type ConfigOptions ¶
type ConfigOptions struct { // 配置类型,native:从本地获取,nacos是从Nacos配置中心获取 Type string `mapstructure:"type" json:"type"` // 本地配置文件路径,如果是nacos,则不需要写 NativePath string `mapstructure:"native-path" json:"native-path"` // 本地配置文件名称,如果是nacos,则不需要写 NativeName string `mapstructure:"native-name" json:"native-name"` // 本地配置文件类型,如果是nacos,则不需要写,支持的类型:ini、json、yaml NativeType string `mapstructure:"native-type" json:"native-type"` // nacos配置中心的配置 Nacos NacosConfig `mapstructure:"nacos" json:"nacos"` }
ConfigOptions 获取主配置的配置文件
func NewConfigOptions ¶
func NewConfigOptions() *ConfigOptions
func (*ConfigOptions) AddFlags ¶
func (c *ConfigOptions) AddFlags(fs *pflag.FlagSet)
func (*ConfigOptions) Validate ¶
func (c *ConfigOptions) Validate() error
type NacosConfig ¶
type NacosConfig struct { Host string `mapstructure:"host" json:"host"` Port int `mapstructure:"port" json:"port"` Namespace string `mapstructure:"namespace" json:"namespace"` User string `mapstructure:"user" json:"user"` Password string `mapstructure:"password" json:"password"` DataId string `mapstructure:"dataid" json:"dataid"` Group string `mapstructure:"group" json:"group"` }
Click to show internal directories.
Click to hide internal directories.