cherryDataConfig

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterParser

func RegisterParser(parser IDataParser)

func RegisterSource

func RegisterSource(dataSource IDataSource)

Types

type Component added in v1.1.1

type Component struct {
	sync.RWMutex
	cherryFacade.Component
	// contains filtered or unexported fields
}

func NewComponent

func NewComponent() *Component

func (*Component) GetBytes added in v1.1.1

func (d *Component) GetBytes(configName string) (data []byte, found bool)

func (*Component) GetDataSource added in v1.1.1

func (d *Component) GetDataSource() IDataSource

func (*Component) GetIConfigFile added in v1.1.1

func (d *Component) GetIConfigFile(name string) IConfig

func (*Component) GetParser added in v1.1.1

func (d *Component) GetParser() IDataParser

func (*Component) Init added in v1.1.1

func (d *Component) Init()

func (*Component) Name added in v1.1.1

func (d *Component) Name() string

Name unique components name

func (*Component) OnStop added in v1.1.1

func (d *Component) OnStop()

func (*Component) Register added in v1.1.1

func (d *Component) Register(configs ...IConfig)

type ConfigChangeFn

type ConfigChangeFn func(configName string, data []byte)

ConfigChangeFn 数据变更时触发该函数

type IConfig

type IConfig interface {
	Name() string                             // 配置名称
	Load(maps interface{}, reload bool) error // 配置序列化后,执行该函数
}

IConfig 配置接口

type IDataConfig

type IDataConfig interface {
	Register(configFile ...IConfig)                       // 注册映射文件
	GetBytes(configName string) (data []byte, found bool) // 获取原始的数据
	GetParser() IDataParser                               // 当前参数配置的数据格式解析器
	GetDataSource() IDataSource                           // 当前参数配置的获取数据源
}

IDataConfig 数据配置接口

type IDataParser

type IDataParser interface {
	TypeName() string                           // 注册名称
	Unmarshal(text []byte, v interface{}) error // 文件格式解析器
}

IDataParser 数据格式解析接口

func GetParser

func GetParser(name string) IDataParser

type IDataSource

type IDataSource interface {
	Name() string                                           // 数据源名称
	Init(dataConfig IDataConfig)                            // 函数初始化时
	ReadBytes(configName string) (data []byte, error error) // 获取数据流
	OnChange(fn ConfigChangeFn)                             // 数据变更时
	Stop()                                                  // 停止
}

IDataSource 配置文件数据源

func GetDataSource

func GetDataSource(name string) IDataSource

type ParserJson

type ParserJson struct {
}

func (*ParserJson) TypeName

func (j *ParserJson) TypeName() string

func (*ParserJson) Unmarshal

func (j *ParserJson) Unmarshal(data []byte, v interface{}) error

type SourceFile

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

SourceFile 本地读取数据配置文件

func (*SourceFile) Init

func (f *SourceFile) Init(_ IDataConfig)

func (*SourceFile) Name

func (f *SourceFile) Name() string

func (*SourceFile) OnChange

func (f *SourceFile) OnChange(fn ConfigChangeFn)

func (*SourceFile) ReadBytes

func (f *SourceFile) ReadBytes(configName string) (data []byte, error error)

func (*SourceFile) Stop

func (f *SourceFile) Stop()

type SourceRedis

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

SourceRedis redis方式获取数据配置

从profile-x.json中获取data_config的属性配置, 如果"data_source"的值为"redis",则启用redis方式读取数据配置. 通过redis的订阅机制来触发哪个配置有变更,则进行重新加载处理. 程序启动后,会订阅“subscribeKey”,当有变更时,则执行加载.

func (*SourceRedis) Init

func (r *SourceRedis) Init(_ IDataConfig)

func (*SourceRedis) Name

func (r *SourceRedis) Name() string

func (*SourceRedis) OnChange

func (r *SourceRedis) OnChange(fn ConfigChangeFn)

func (*SourceRedis) ReadBytes

func (r *SourceRedis) ReadBytes(configName string) (data []byte, error error)

func (*SourceRedis) Stop

func (r *SourceRedis) Stop()

Jump to

Keyboard shortcuts

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