config

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 34 Imported by: 19

Documentation

Index

Constants

View Source
const (
	Apollo = "apollo"
)
View Source
const (
	RemoteReaderSetError = "cannot set key in remote reader"
)

Variables

This section is empty.

Functions

func AddChangeListener added in v0.0.31

func AddChangeListener(listener ChangeListener)

func Close

func Close()

Close 关闭配置监听

func Get

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

Get 获取配置值

func GetBoolKV added in v0.0.31

func GetBoolKV(key string, defaultVal bool) bool

func GetCacheVersion added in v0.0.31

func GetCacheVersion(defaultVal int) int

func GetChangeListeners added in v0.0.31

func GetChangeListeners() *list.List

func GetConsulConfig added in v0.0.31

func GetConsulConfig(key string) ([]byte, bool)

func GetConsulConfigRemote added in v0.0.31

func GetConsulConfigRemote(key string) ([]byte, error)

default http timeout, take care

func GetConsulKV added in v0.0.31

func GetConsulKV(key string) (string, error)

func GetDurationKV added in v0.0.31

func GetDurationKV(key string, defaultVal time.Duration) time.Duration

func GetIntKV added in v0.0.31

func GetIntKV(key string, defaultVal int) int

func GetMapKV added in v0.0.31

func GetMapKV[T any](key string) (map[string]T, error)

func GetStringKV added in v0.0.31

func GetStringKV(key string, defaultVal string) string

func GetStringMapKV added in v0.0.31

func GetStringMapKV(key string) (map[string]string, error)

func GetStringSliceKV added in v0.0.31

func GetStringSliceKV(key string) ([]string, error)

func GetStructKV added in v0.0.31

func GetStructKV[T any](key string) (*T, error)

func Has

func Has(pattern string) bool

Has 是否存在配置

func HasKey added in v0.0.31

func HasKey[T any](dict map[string]T, key string) bool

func InitConsulConfig added in v0.0.31

func InitConsulConfig(ctx context.Context)

func PutConsulConfig added in v0.0.31

func PutConsulConfig(key string, value []byte) error

func PutConsulKV added in v0.0.31

func PutConsulKV(key, value string) error

func RemoveChangeListener added in v0.0.31

func RemoveChangeListener(listener ChangeListener)

func Set

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

Set 设置配置值

func SetReader

func SetReader(reader Reader)

SetReader 设置配置读取器

Types

type ApolloReader added in v0.0.31

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

func NewApolloReader added in v0.0.31

func NewApolloReader(opts ...RemoteReaderOption) *ApolloReader

func (*ApolloReader) AddChangeListener added in v0.0.31

func (r *ApolloReader) AddChangeListener(listener storage.ChangeListener)

AddChangeListener 设置远端配置变更监听

func (*ApolloReader) Close added in v0.0.31

func (r *ApolloReader) Close()

Close 关闭配置监听

func (*ApolloReader) Get added in v0.0.31

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

Get 获取配置值

func (*ApolloReader) Has added in v0.0.31

func (r *ApolloReader) Has(pattern string) bool

Has 是否存在配置

func (*ApolloReader) Range added in v0.0.31

func (r *ApolloReader) Range(f func(key, value interface{}) bool)

Range 遍历所有key

func (*ApolloReader) RemoveChangeListener added in v0.0.31

func (r *ApolloReader) RemoveChangeListener(listener storage.ChangeListener)

RemoveChangeListener 取消远端配置变更监听

func (*ApolloReader) Set added in v0.0.31

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

Set 设置配置值

type ChangeListener added in v0.0.31

type ChangeListener interface {
	//OnChange 增加变更监控
	OnChange(changes map[string]*ConfigChange)
}

ChangeListener 监听器

type ConfigChange added in v0.0.31

type ConfigChange struct {
	OldValue   []byte
	NewValue   []byte
	ChangeType ConfigChangeType
}

type ConfigChangeType added in v0.0.31

type ConfigChangeType int

config change type

const (
	ADDED ConfigChangeType = iota
	MODIFIED
	DELETED
)

type Configuration

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

Configuration 配置项

type CustomChangeListener added in v0.0.31

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

func (*CustomChangeListener) OnChange added in v0.0.31

func (c *CustomChangeListener) OnChange(changeEvent *storage.ChangeEvent)

func (*CustomChangeListener) OnNewestChange added in v0.0.31

func (c *CustomChangeListener) OnNewestChange(event *storage.FullChangeEvent)

type Decoder

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

type Map added in v0.0.31

type Map[T any] struct {
	// contains filtered or unexported fields
}

func NewMap added in v0.0.31

func NewMap[T any]() *Map[T]

func (*Map[T]) Add added in v0.0.31

func (cache *Map[T]) Add(id string, item T)

func (*Map[T]) AddAll added in v0.0.31

func (cache *Map[T]) AddAll(itemMap map[string]T)

func (*Map[T]) AddChangeListener added in v0.0.31

func (cache *Map[T]) AddChangeListener(listener ChangeListener)

AddChangeListener 增加变更监控

func (*Map[T]) Clear added in v0.0.31

func (cache *Map[T]) Clear(id string)

func (*Map[T]) ClearAll added in v0.0.31

func (cache *Map[T]) ClearAll()

func (*Map[T]) Get added in v0.0.31

func (cache *Map[T]) Get(id string) (T, bool)

func (*Map[T]) GetChangeListeners added in v0.0.31

func (cache *Map[T]) GetChangeListeners() *list.List

GetChangeListeners 获取配置修改监听器列表

func (*Map[T]) RemoveChangeListener added in v0.0.31

func (cache *Map[T]) RemoveChangeListener(listener ChangeListener)

RemoveChangeListener 删除变更监控

func (*Map[T]) ResetAll added in v0.0.31

func (cache *Map[T]) ResetAll(itemMap map[string]T)

func (*Map[T]) ToMap added in v0.0.31

func (cache *Map[T]) ToMap() map[string]T

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 WithRemoteSources added in v0.0.31

func WithRemoteSources(remoteSources ...string) Option

WithRemoteSources 设置远程配置源

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
	// AddChangeListener 设置配置变更监听
	AddChangeListener(listener interface{})
	// RemoveChangeListener 设置配置变更监听
	RemoveChangeListener(listener interface{})
	// Close 关闭配置监听
	Close()
}

func GetReader

func GetReader() Reader

GetReader 获取配置读取器

func NewReader

func NewReader(opts ...Option) Reader

type RemoteReaderOption added in v0.0.31

type RemoteReaderOption func(o *remoteReaderOptions)

func WithAppId added in v0.0.31

func WithAppId(appId string) RemoteReaderOption

WithAppId 设置上下文

func WithHost added in v0.0.31

func WithHost(host string) RemoteReaderOption

WithHost 设置上下文

func WithNamespace added in v0.0.31

func WithNamespace(namespace string) RemoteReaderOption

WithNamespace 设置上下文

func WithPort added in v0.0.31

func WithPort(port int) RemoteReaderOption

WithPort 设置上下文

type Source

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

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