easyconfig

package
v0.0.0-...-6bbb419 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T ConfigurationBean](prop Properties) T

Get 根据泛型类型获取配置对象 由于 ConfigurationBean 的唯一实现类 ConfigurationProperties 指定了指针实现 所以泛型T约束了只能是指针对象

Types

type ConfigurationBean

type ConfigurationBean interface {
	// contains filtered or unexported methods
}

ConfigurationBean 配置类接口,标识结构体为一个配置类

type ConfigurationBeanDefinition

type ConfigurationBeanDefinition struct {
	Prefix              string // 配置属性的前缀
	IgnoreInvalidFields bool   // 忽略无法转换的无效的属性(即忽略那些配置中属性类型无法转换为结构体属性类型的字段)
	AutoRefresh         bool   // 当配置发生变化时,是否自动刷新
	CompleteName        string // 配置类全路径名称
	Name                string // 配置类名称
}

ConfigurationBeanDefinition 解析ConfigurationProperties注解的定义信息

func ResolveConfigurationBean

func ResolveConfigurationBean[T ConfigurationBean](configBean T) ConfigurationBeanDefinition

ResolveConfigurationBean 解析配置类 ConfigurationBean 的注解元信息

type ConfigurationProperties

type ConfigurationProperties struct {
}

ConfigurationProperties ConfigurationBean的唯一实现类,提供注解的作用 所有需要标记为配置类的结构体都必须将 ConfigurationProperties 定义为该结构体的内嵌属性,这样才能间接实现 ConfigurationBean 接口

type Properties

type Properties interface {

	// Get 同viper.Get()方法
	Get(key string) any

	// GetString 同viper.GetString()方法
	GetString(key string) string

	// GetInt 同viper.GetInt()方法
	GetInt(key string) int

	// GetInt64 同viper.GetInt64()方法
	GetInt64(key string) int64

	// GetFloat64 同viper.GetFloat64()方法
	GetFloat64(key string) float64

	// GetBool 同viper.GetBool()方法
	GetBool(key string) bool

	// GetConfigBean 根据反射类型查询配置类对象
	GetConfigBean(rt reflect.Type) ConfigurationBean

	// GetConfigBeans 返回所有配置类对象
	GetConfigBeans() []ConfigurationBean
}

Properties 配置核心接口,也是easyconfig的核心

type PropertiesBuilder

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

PropertiesBuilder properties构建对象

func Builder

func Builder() *PropertiesBuilder

func (*PropertiesBuilder) AddConfigBeans

func (my *PropertiesBuilder) AddConfigBeans(configBeans ...ConfigurationBean) *PropertiesBuilder

func (*PropertiesBuilder) AddFiles

func (my *PropertiesBuilder) AddFiles(files ...string) *PropertiesBuilder

func (*PropertiesBuilder) AddWatcher

func (my *PropertiesBuilder) AddWatcher(watchers ...WatchHandler) *PropertiesBuilder

func (*PropertiesBuilder) Build

func (my *PropertiesBuilder) Build() Properties

func (*PropertiesBuilder) CloseLog

func (my *PropertiesBuilder) CloseLog() *PropertiesBuilder

func (*PropertiesBuilder) LogLevel

func (my *PropertiesBuilder) LogLevel(level logger.LogLevel) *PropertiesBuilder

type WatchHandler

type WatchHandler func(params []WatcherParam, conf2DefinitionMap map[ConfigurationBean]ConfigurationBeanDefinition)

WatchHandler 定义easyconfig配置监测处理器

type WatcherParam

type WatcherParam struct {
	Key    string // 配置发生改变的key
	OldVal any    // 配置改变前的值
	NewVal any    // 配置改变后的值
}

WatcherParam 定义easyconfig监视器参数

Jump to

Keyboard shortcuts

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