Documentation ¶
Index ¶
- type ConsulConfig
- type MysqlConfig
- type NacosConfig
- type ServiceConfig
- type Viper
- func (v *Viper) Get(key string) (value interface{})
- func (v *Viper) GetEnvBool(envName string) (flag bool)
- func (v *Viper) ReadConfig(configFilePath string, configStruct interface{}) (err error)
- func (v *Viper) ReadConsul(config ConsulConfig) (err error)
- func (v *Viper) Update(key string, value interface{})
- func (v *Viper) WatchConfig(configFilePath string, configStruct interface{}) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsulConfig ¶
type ConsulConfig struct { Host string `mapstructure:"host" json:"host"` // consul主机地址 Port uint16 `mapstructure:"port" json:"port"` // consul端口号 Key string `mapstructure:"key" json:"key"` // key Type string `mapstructure:"type" json:"type"` // 类型:json,yaml // contains filtered or unexported fields }
ConsulConfig 读取consul的配置信息
type MysqlConfig ¶
type MysqlConfig struct { Host string `mapstructure:"host" json:"host"` // 主机地址 Port int `mapstructure:"port" json:"port"` // 端口号 Name string `mapstructure:"db" json:"database"` // 数据库名称 User string `mapstructure:"user" json:"username"` // 用户名 Password string `mapstructure:"password" json:"password"` // 密码 }
MysqlConfig MySQL配置信息
type NacosConfig ¶
type NacosConfig struct { Host string `mapstructure:"host" json:"host"` // nacos主机 Port uint64 `mapstructure:"port" json:"port"` // nacos端口 Namespace string `mapstructure:"namespace" json:"namespace"` // 名称空间 User string `mapstructure:"user" json:"user"` // 用户名 Password string `mapstructure:"password" json:"password"` // 密码 DataId string `mapstructure:"dataid" json:"data_id"` // 配置名 Group string `mapstructure:"group" json:"group"` // 组名 }
NacosConfig nacos配置
type ServiceConfig ¶
type ServiceConfig struct { Name string `mapstructure:"name" json:"name"` // 服务名 Host string `mapstructure:"host" json:"host"` // 主机地址 Port uint16 `mapstructure:"port" json:"port"` // 服务端口号 Tags []string `mapstructure:"tags" json:"tags"` // 服务标签列表 MysqlInfo MysqlConfig `mapstructure:"mysql" json:"mysql"` // mysql配置 ConsulInfo ConsulConfig `mapstructure:"consul" json:"consul"` // consul配置 }
ServiceConfig Service服务配置
type Viper ¶
type Viper struct {
// contains filtered or unexported fields
}
Viper viper配置核心对象
func (*Viper) GetEnvBool ¶
GetEnvBool 读取bool类型环境变量 @param envName 环境变量名称 @return flag 读取结果
func (*Viper) ReadConfig ¶
ReadConfig 读取配置 @param configFilePath 配置文件路径 @param configStruct 配置文件对应的结构体 @return err 读取成功返回nil,读取失败返回失败信息
func (*Viper) ReadConsul ¶
func (v *Viper) ReadConsul(config ConsulConfig) (err error)
ReadConsul 读取consul配置 @param config consul的配置信息 @param configStruct 配置对应的结构体 @return err 成功返回nil,失败返回错误信息
func (*Viper) WatchConfig ¶
WatchConfig 监听配置文件变化 @param configFilePath 配置文件路径 @param configStruct 配置文件对应的结构体 @return err 读取成功返回nil,读取失败返回失败信息
Click to show internal directories.
Click to hide internal directories.