Documentation
¶
Index ¶
- func GetConfigValue[T any](key string, defaultValue T) T
- func IsProduction() bool
- func ParseDuration(value string) time.Duration
- type ConfigComponent
- func (c *ConfigComponent) Get(key string) interface{}
- func (c *ConfigComponent) GetBool(key string) bool
- func (c *ConfigComponent) GetInt(key string) int
- func (c *ConfigComponent) GetInt32(key string) int32
- func (c *ConfigComponent) GetInt64(key string) int64
- func (c *ConfigComponent) GetString(key string) string
- func (c *ConfigComponent) GetStringMap(key string) map[string]any
- func (c *ConfigComponent) GetStringSlice(key string) []string
- func (c *ConfigComponent) GetStringTimeDuration(key string) time.Duration
- func (c *ConfigComponent) GetUint(key string) uint
- func (c *ConfigComponent) GetViper() *viper.Viper
- func (c *ConfigComponent) Load() error
- func (c *ConfigComponent) Unmarshal(rawVal interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfigValue ¶
@title 获取配置值, 独立方法 @description 获取配置值,如果配置不存在则返回默认值 @param key string 配置名 @param defaultValue interface{} any @return interface{} any
func ParseDuration ¶ added in v1.3.0
将字符串值解析为 time.Duration
用于已从配置解析出的字符串值,如 "1h", "30m", "5s"
@param value string 时间字符串 @return time.Duration 时间
Types ¶
type ConfigComponent ¶
type ConfigComponent struct {
// contains filtered or unexported fields
}
配置组件
func MustLoadFile ¶ added in v1.3.0
func MustLoadFile(configFile string) *ConfigComponent
加载配置文件(单例),如果出错则panic
@param configFile string 配置文件完整路径,如: ./config/frame-server.yml @return *ConfigComponent 配置组件
func NewConfig ¶
func NewConfig(configFile string) *ConfigComponent
创建配置组件
@param configFile string 配置文件完整路径,如: ./config/frame-server.yml
func (*ConfigComponent) Get ¶
func (c *ConfigComponent) Get(key string) interface{}
获取配置
@param key string 配置名 @return interface{} 配置值
func (*ConfigComponent) GetInt32 ¶ added in v1.0.8
func (c *ConfigComponent) GetInt32(key string) int32
GetInt32 获取int32配置
func (*ConfigComponent) GetInt64 ¶ added in v1.0.8
func (c *ConfigComponent) GetInt64(key string) int64
获取int64配置
func (*ConfigComponent) GetString ¶
func (c *ConfigComponent) GetString(key string) string
获取字符串配置
@param key string 配置名 @return string 字符串
func (*ConfigComponent) GetStringMap ¶
func (c *ConfigComponent) GetStringMap(key string) map[string]any
获取字符串映射
@param key string 配置名 @return map[string]any 字符串映射
func (*ConfigComponent) GetStringSlice ¶
func (c *ConfigComponent) GetStringSlice(key string) []string
获取字符串切片
@param key string 配置名 @return []string 字符串切片
func (*ConfigComponent) GetStringTimeDuration ¶ added in v1.0.4
func (c *ConfigComponent) GetStringTimeDuration(key string) time.Duration
获取字符串时间
@param key string 配置名 @return time.Duration 时间
func (*ConfigComponent) GetUint ¶ added in v1.0.8
func (c *ConfigComponent) GetUint(key string) uint
获取uint配置
func (*ConfigComponent) GetViper ¶
func (c *ConfigComponent) GetViper() *viper.Viper
获取Viper实例
@return *viper.Viper Viper实例
func (*ConfigComponent) Unmarshal ¶
func (c *ConfigComponent) Unmarshal(rawVal interface{}) error
将配置反序列化到结构体
@param rawVal interface{} 结构体 @return error 错误