Documentation
¶
Index ¶
- Variables
- func Decode(dst any, mapData map[string]any, opts ...DecoderConfigOption) error
- func GetRegisteredConfigCenter() map[string]ConfigCenter
- func NewGlobal[C Config, D Dao](configCenter ...ConfigCenter) *globalConfig[C, D]
- func NewGlobalConfig[C Config](configCenter ...ConfigCenter) *globalConfig[C, *EmbeddedPresets]
- func NewGlobalWith[C Config, D Dao](conf C, dao D, configCenter ...ConfigCenter) *globalConfig[C, D]
- func RegisterConfigCenter(c ConfigCenter)
- func RegisterUnSupportTemplateTypes(types ...string)
- func Start[C Config, D Dao](conf C, dao D, configCenter ...ConfigCenter) func()
- type BasicConfig
- type Client
- type CloseFunc
- type Config
- type ConfigCenter
- type ConfigCenterConfig
- type ConfigType
- type Dao
- type DaoConfig
- type DaoField
- type DaoG
- type DecoderConfigOption
- type EmbeddedPresets
- type EnvConfig
- type Init
- type Local
- type LogConfig
- type RootConfig
Constants ¶
This section is empty.
Variables ¶
var DaoFieldType = reflect.TypeOf((*DaoField)(nil)).Elem()
var EmbeddedPresetsType = reflect.TypeOf((*EmbeddedPresets)(nil)).Elem()
Functions ¶
func Decode ¶ added in v0.13.5
func Decode(dst any, mapData map[string]any, opts ...DecoderConfigOption) error
Decode decodes a map[string]any into dst using mapstructure with the default decoder options.
func GetRegisteredConfigCenter ¶ added in v0.13.12
func GetRegisteredConfigCenter() map[string]ConfigCenter
GetRegisteredConfigCenter returns a snapshot copy of all currently registered ConfigCenter instances.
func NewGlobal ¶ added in v0.4.0
func NewGlobal[C Config, D Dao](configCenter ...ConfigCenter) *globalConfig[C, D]
NewGlobal creates a globalConfig by allocating zero-value instances of C and D via reflection, then runs the full initialization sequence. var Global = initialize.NewGlobal[C,D]()
func NewGlobalConfig ¶ added in v0.9.0
func NewGlobalConfig[C Config](configCenter ...ConfigCenter) *globalConfig[C, *EmbeddedPresets]
NewGlobalConfig is a shortcut for applications that only need a Config (no custom Dao).
func NewGlobalWith ¶ added in v0.4.0
func NewGlobalWith[C Config, D Dao](conf C, dao D, configCenter ...ConfigCenter) *globalConfig[C, D]
NewGlobalWith creates a globalConfig with the provided Config and Dao instances and immediately runs the full initialization sequence.
func RegisterConfigCenter ¶ added in v0.13.12
func RegisterConfigCenter(c ConfigCenter)
RegisterConfigCenter registers a ConfigCenter implementation by its type name (lowercase letters only). Duplicate registrations are silently ignored.
func RegisterUnSupportTemplateTypes ¶ added in v0.12.0
func RegisterUnSupportTemplateTypes(types ...string)
RegisterUnSupportTemplateTypes appends additional type name strings that should be excluded from config template generation (e.g. types that cannot be marshaled generically).
func Start ¶
func Start[C Config, D Dao](conf C, dao D, configCenter ...ConfigCenter) func()
Start is a convenience wrapper around NewGlobalWith that returns only the Cleanup function.
Types ¶
type BasicConfig ¶ added in v0.13.12
type BasicConfig struct {
// 模块名
Name string `flag:"name:name;usage:模块名;env:NAME"`
// environment
Env string `flag:"name:env;short:e;default:dev;usage:环境;env:ENV"`
}
BasicConfig
type Config ¶
type Config interface {
// contains filtered or unexported methods
}
Config is the interface that application configs must implement. BeforeInject sets default values before unmarshaling; AfterInject runs post-unmarshal initialization.
type ConfigCenter ¶ added in v0.13.12
type ConfigCenter interface {
Config() any
io.Closer
Handle(ctx context.Context, merge func(io.Reader) error, onChange func(io.Reader) error) error
Type() string
}
func GetConfigCenter ¶ added in v0.13.12
func GetConfigCenter(configType string) ConfigCenter
GetConfigCenter returns the registered ConfigCenter for the given type string, or nil if not found.
type ConfigCenterConfig ¶ added in v0.13.12
type ConfigCenterConfig struct {
// 配置格式
Format string `flag:"name:format;usage:配置格式"`
// 配置类型
Type string `flag:"name:conf_type;usage:配置类型"`
// config字段顺序不能变,ConfigCenter 保持在最后
ConfigCenter ConfigCenter
}
type ConfigType ¶ added in v0.13.12
type ConfigType string
type Dao ¶
type Dao interface {
// contains filtered or unexported methods
}
Dao is the interface that DAO structs must implement. AfterInjectConfig runs after config is unmarshaled; AfterInject runs after all DAO fields are initialized.
type DaoG ¶ added in v0.13.12
type DaoG[C DaoConfig[D], D any] struct { Conf C Client *D // contains filtered or unexported fields }
func (*DaoG[C, D]) Close ¶ added in v0.13.12
Close calls the cleanup function returned by Build, if any.
type DecoderConfigOption ¶ added in v0.13.5
type DecoderConfigOption func(*mapstructure.DecoderConfig)
type EmbeddedPresets ¶
type EmbeddedPresets struct {
}
func (*EmbeddedPresets) AfterInject ¶ added in v0.0.33
func (u *EmbeddedPresets) AfterInject()
AfterInject is a no-op placeholder satisfying the Config/Dao interface.
func (*EmbeddedPresets) AfterInjectConfig ¶ added in v0.0.33
func (u *EmbeddedPresets) AfterInjectConfig()
AfterInjectConfig is a no-op placeholder satisfying the Dao interface.
func (*EmbeddedPresets) BeforeInject ¶ added in v0.0.33
func (u *EmbeddedPresets) BeforeInject()
BeforeInject is a no-op placeholder satisfying the Config/Dao interface.
type EnvConfig ¶ added in v0.13.12
type EnvConfig struct {
Debug bool `flag:"name:debug;short:d;default:true;usage:是否测试;env:DEBUG"`
ConfigTemplateDir string `flag:"name:conf_tmpl_dir;usage:是否生成配置模板;env:CONFIG_TEMPLATE_DIR"`
// 代理, socks5://localhost:1080
Proxy string `flag:"name:proxy;usage:代理;env:HTTP_PROXY" `
SkipInjectDaos []string `flag:"name:skip_inject_daos;usage:跳过注入的dao"`
LocalConfig Local
// config字段顺序不能变,ConfigCenter 保持在最后
ConfigCenter ConfigCenterConfig
}
func (*EnvConfig) AfterInject ¶ added in v0.13.12
func (c *EnvConfig) AfterInject()
AfterInject sets up the HTTP proxy from the Proxy field and resolves all local config paths to absolute paths.
type Local ¶ added in v0.6.0
func (*Local) Config ¶ added in v0.6.0
Config returns the Local struct itself as its own configuration.
type LogConfig ¶ added in v0.13.12
全局变量,只一个实例,只提供config
func (*LogConfig) AfterInjectWithRoot ¶ added in v0.13.12
func (c *LogConfig) AfterInjectWithRoot(rootconfig *RootConfig)
AfterInjectWithRoot configures and replaces the default global logger using the root config's Name and Debug fields. It is a no-op if the config is still fully zero-valued.
type RootConfig ¶ added in v0.13.12
type RootConfig struct {
Executable string `init:"-"` // autowired
ExecDir string `init:"-"` // autowired
// 配置文件路径
ConfPath string `flag:"name:config;short:c;usage:配置文件路径,默认./config.xxx或./config/config.xxx;env:CONFIG"`
BasicConfig
EnvConfig
}
