config

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigValue

func GetConfigValue[T any](key string, defaultValue T) T

@title 获取配置值, 独立方法 @description 获取配置值,如果配置不存在则返回默认值 @param key string 配置名 @param defaultValue interface{} any @return interface{} any

func IsProduction

func IsProduction() bool

IsProduction 判断是否是生产环境

func SetGlobalConfig

func SetGlobalConfig(c *ConfigComponent)

SetGlobalConfig 设置全局配置实例

Types

type ConfigComponent

type ConfigComponent struct {
	// contains filtered or unexported fields
}

ConfigComponent 配置组件

func GetConfig

func GetConfig() *ConfigComponent

GetGlobalConfig 获取全局配置实例

func MustLoad

func MustLoad(confName, confPath string) *ConfigComponent

MustLoad 创建并加载配置,如果出错则panic

func NewConfig

func NewConfig(confName, confPath string) *ConfigComponent

NewConfig 创建配置组件

func (*ConfigComponent) Get

func (c *ConfigComponent) Get(key string) interface{}

Get 获取配置

func (*ConfigComponent) GetBool

func (c *ConfigComponent) GetBool(key string) bool

GetBool 获取布尔配置

func (*ConfigComponent) GetInt

func (c *ConfigComponent) GetInt(key string) int

GetInt 获取整数配置

func (*ConfigComponent) GetSrtingTimeDuration

func (c *ConfigComponent) GetSrtingTimeDuration(key string) time.Duration

func (*ConfigComponent) GetString

func (c *ConfigComponent) GetString(key string) string

GetString 获取字符串配置

func (*ConfigComponent) GetStringMap

func (c *ConfigComponent) GetStringMap(key string) map[string]any

func (*ConfigComponent) GetStringSlice

func (c *ConfigComponent) GetStringSlice(key string) []string

func (*ConfigComponent) GetViper

func (c *ConfigComponent) GetViper() *viper.Viper

GetViper 获取Viper实例

func (*ConfigComponent) Load

func (c *ConfigComponent) Load() error

Start 启动配置组件

func (*ConfigComponent) Unmarshal

func (c *ConfigComponent) Unmarshal(rawVal interface{}) error

Unmarshal 将配置反序列化到结构体

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL