config

package
v0.0.0-...-bb8bcd8 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CfgLoader

type CfgLoader interface {
	LoadConfig(ctx context.Context) (*entity.AppConf, error)
	GetConfigPath() string
}

CfgLoader 接口的定义需要根据你的实际需求来实现。

type CfgManager

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

CfgManager 管理配置加载和监听配置变化,以及通知其他部分应用程序的错误。

func NewConfigManager

func NewConfigManager(loader CfgLoader, watcher WatcherInterface, logger *zap.Logger, retryPolicy RetryPolicy) *CfgManager

NewConfigManager 创建新的配置管理器

func (*CfgManager) AddWatcher

func (cm *CfgManager) AddWatcher(filePath string) error

AddWatcher 添加配置监听器

func (*CfgManager) GetConfig

func (cm *CfgManager) GetConfig() *entity.AppConf

GetConfig 获取当前的配置

func (*CfgManager) Init

func (cm *CfgManager) Init(ctx context.Context) error

Init 初始化配置加载和更新机制

func (*CfgManager) ListenForConfigErrors

func (cm *CfgManager) ListenForConfigErrors() <-chan error

ListenForConfigErrors 监听配置错误

func (*CfgManager) RemoveWatcher

func (cm *CfgManager) RemoveWatcher(filePath string) error

RemoveWatcher 移除监听器

type CfgParser

type CfgParser interface {
	Parse(file afero.File) (*entity.AppConf, error)
}

CfgParser 配置解析器

func NewParser

func NewParser(fileExtension string, logger *zap.Logger) (CfgParser, error)

NewParser 创建新的配置解析器

type FsNotifyWatcher

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

func NewFsNotifyWatcher

func NewFsNotifyWatcher(w WatcherInterface) *FsNotifyWatcher

func (*FsNotifyWatcher) Add

func (f *FsNotifyWatcher) Add(path string) error

func (*FsNotifyWatcher) Close

func (f *FsNotifyWatcher) Close() error

func (*FsNotifyWatcher) Errors

func (f *FsNotifyWatcher) Errors() <-chan error

func (*FsNotifyWatcher) Events

func (f *FsNotifyWatcher) Events() <-chan fsnotify.Event

func (*FsNotifyWatcher) Remove

func (f *FsNotifyWatcher) Remove(path string) error

type JSONParser

type JSONParser struct {
	Logger *zap.Logger
}

JSONParser JSON配置解析器

func (*JSONParser) Parse

func (j *JSONParser) Parse(file afero.File) (*entity.AppConf, error)

Parse 解析json配置文件

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int           // 最大重试次数
	Timeout     time.Duration // 超时时间
}

RetryPolicy 重试策略

type WatcherInterface

type WatcherInterface interface {
	Add(name string) error
	Remove(name string) error
	Close() error
	Events() <-chan fsnotify.Event
	Errors() <-chan error
}

WatcherInterface 定义了 fsnotify.Watcher 需要模拟的方法

type YAMLParser

type YAMLParser struct {
	Logger *zap.Logger
}

YAMLParser YAML配置解析器

func (*YAMLParser) Parse

func (y *YAMLParser) Parse(file afero.File) (*entity.AppConf, error)

Parse 解析yaml配置文件

Jump to

Keyboard shortcuts

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