config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const EnvConfigAddress = "CONFIG_ADDRESS"
View Source
const EnvConfigKEY = "CONFIG_KEY"
View Source
const EnvConfigPath = "CONFIG_PATH"

Variables

This section is empty.

Functions

func GetByTree

func GetByTree(key string) ([]byte, error)

func GetLocalConfigPath

func GetLocalConfigPath() string

Get the local config file path from the command line

Types

type Config

type Config struct {
	*viper.Viper
	// contains filtered or unexported fields
}

Config 配置管理

func NewConfig

func NewConfig(ConfigPath string) (*Config, error)

func (*Config) AddChangeCallback added in v0.2.0

func (c *Config) AddChangeCallback(callback func())

AddChangeCallback 添加配置变更回调

func (*Config) DisableHotReload added in v0.2.0

func (c *Config) DisableHotReload() *Config

DisableHotReload 禁用热重载

func (*Config) EnableHotReload added in v0.2.0

func (c *Config) EnableHotReload() *Config

EnableHotReload 启用热重载(文件配置专用)

func (*Config) GetBoolWithDefault added in v0.2.0

func (c *Config) GetBoolWithDefault(key string, defaultValue bool) bool

GetBoolWithDefault 获取布尔配置值,如果不存在则返回默认值

func (*Config) GetIntWithDefault added in v0.2.0

func (c *Config) GetIntWithDefault(key string, defaultValue int) int

GetIntWithDefault 获取整数配置值,如果不存在则返回默认值

func (*Config) GetStringWithDefault added in v0.2.0

func (c *Config) GetStringWithDefault(key, defaultValue string) string

GetStringWithDefault 获取字符串配置值,如果不存在则返回默认值

func (*Config) GetWithDefault added in v0.2.0

func (c *Config) GetWithDefault(key string, defaultValue interface{}) interface{}

GetWithDefault 获取配置值,如果不存在则返回默认值

func (*Config) IsHotReloadEnabled added in v0.2.0

func (c *Config) IsHotReloadEnabled() bool

IsHotReloadEnabled 检查是否启用了热重载

func (*Config) ReloadConfig added in v0.2.0

func (c *Config) ReloadConfig() error

ReloadConfig 手动重新加载配置

func (*Config) RemoveAllCallbacks added in v0.2.0

func (c *Config) RemoveAllCallbacks()

RemoveAllCallbacks 清除所有配置变更回调

func (*Config) SetHotReloadInterval added in v0.2.0

func (c *Config) SetHotReloadInterval(intervalSeconds int) *Config

SetHotReloadInterval 设置热重载轮询间隔(仅对Consul配置有效) intervalSeconds: 轮询间隔秒数,-1或0表示禁用热重载,>0表示启用并设置间隔

func (*Config) Validate added in v0.2.0

func (c *Config) Validate() error

Validate 验证配置

func (*Config) WatchConfig added in v0.2.0

func (c *Config) WatchConfig()

WatchConfig 监听配置变更(只有启用热重载时才生效)

Jump to

Keyboard shortcuts

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