configs

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfNotExistError = errors.New("Config key is not exist.")
	ConfValueSetError = errors.New("Config value can not be set.")
	ParseFlagsError   = errors.New("Parse command flags error.")
)

Functions

This section is empty.

Types

type Config

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

func (*Config) OnChange

func (c *Config) OnChange(callback func(any))

OnChange 注册配置变更回调函数

func (*Config) SetByString

func (c *Config) SetByString(value string) error

SetByString 从字符串解析并设置配置值

func (*Config) SetByValue

func (c *Config) SetByValue(value any) error

SetByValue 直接设置配置值

type Manager

type Manager[T any] struct {
	// contains filtered or unexported fields
}

Manager 配置管理器,支持从环境变量、命令行参数和动态映射中加载配置 优先级:默认值 < 环境变量 < 命令行参数 < 动态映射

func NewManager

func NewManager[T any](def *T) (*Manager[T], error)

NewManager 创建配置管理器,自动解析环境变量和命令行参数

func (*Manager[T]) Conf

func (m *Manager[T]) Conf(confKey string) (*Config, error)

Conf 根据配置键获取配置对象

func (*Manager[T]) ParseMap

func (m *Manager[T]) ParseMap(data map[string]string)

ParseMap 从map中解析并更新配置值,键为字段名(区分大小写)

func (*Manager[T]) Raws

func (m *Manager[T]) Raws() *T

Raws 返回配置的原始指针(线程不安全)

func (*Manager[T]) Vars

func (m *Manager[T]) Vars() T

Vars 返回配置的只读副本

Jump to

Keyboard shortcuts

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