config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Apache-2.0 Imports: 21 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close 关闭配置监听

func Get

func Get(pattern string, def ...interface{}) value.Value

Get 获取配置值

func Has

func Has(pattern string) bool

Has 是否存在配置

func Set

func Set(pattern string, value interface{}) error

Set 设置配置值

func SetReader

func SetReader(reader Reader)

SetReader 设置配置读取器

Types

type Configuration

type Configuration struct {
	Name    string
	Format  string
	Content []byte
}

Configuration 配置项

type Decoder

type Decoder func(configuration *Configuration) (interface{}, error)

type Option

type Option func(o *options)

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文

func WithDecoder

func WithDecoder(decoder Decoder) Option

WithDecoder 设置解码器

func WithSources

func WithSources(sources ...Source) Option

WithSources 设置配置源

type Reader

type Reader interface {
	// Has 是否存在配置
	Has(pattern string) bool
	// Get 获取配置值
	Get(pattern string, def ...interface{}) value.Value
	// Set 设置配置值
	Set(pattern string, value interface{}) error
	// Close 关闭配置监听
	Close()
}

func GetReader

func GetReader() Reader

GetReader 获取配置读取器

func NewReader

func NewReader(opts ...Option) Reader

type Source

type Source interface {
	// Load 加载配置项
	Load() ([]*Configuration, error)
	// Watch 监听配置项
	Watch(ctx context.Context) (Watcher, error)
}

func NewSource

func NewSource(path string) Source

type Watcher

type Watcher interface {
	// Next 返回服务实例列表
	Next() ([]*Configuration, error)
	// Stop 停止监听
	Stop() error
}

Jump to

Keyboard shortcuts

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