iface

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 5 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotModified       = errors.New("not modified")
	ErrWaitTimeout       = errors.New("wait timeout")
	ErrConfigNotFound    = errors.New("not exists")
	ErrInvalidConfigKey  = errors.New("invalid config key")
	ErrItemNotFound      = errors.New("item not found")
	ErrNoItemInitializer = errors.New("item initializer not available")
)

Functions

This section is empty.

Types

type ConfigChange

type ConfigChange struct {
	Type      ConfigChangeType
	ConfigKey string
	OldValue  ConfigValue
	NewValue  ConfigValue
}

ConfigChange defines the change of a ConfigValue.

type ConfigChangeListener

type ConfigChangeListener func(change ConfigChange)

ConfigChangeListener defines the callback function when a ConfigValue is changed.

type ConfigChangeType

type ConfigChangeType = int

ConfigChangeType is an enumeration that represents the different types of config changes that can occur. Possible values are ConfigChangeTypeAdd, ConfigChangeTypeUpdate, and ConfigChangeTypeDelete.

const (
	ConfigChangeTypeAdd    ConfigChangeType = 1
	ConfigChangeTypeUpdate ConfigChangeType = 2
	ConfigChangeTypeDelete ConfigChangeType = 3
)

type ConfigManagerIface

type ConfigManagerIface interface {
	GetProvider() ConfigProvider
	RegisterConfigChangeListener(identifier string, listener ConfigChangeListener)
	DeregisterConfigChangeListener(identifier string)
	Refresh() RefreshCompleteSignal
	RefreshAndWait() error
	GetConfig(key string) (ConfigValue, error)
	GetConfigItem(key string, itemType ItemType) (ConfigValueItem, error)
	GetAllConfig() map[string]ConfigValue
	Dump(filepath string) error
}

ConfigManagerIface defines the interface of a Config Manager

type ConfigProvider

type ConfigProvider interface {
	// LoadConfig should return a full set of config, or an error if failed. currentConfig is given as a
	// 2nd parameter so that the Not-Modified strategy of some provider (if applicable) can be used.
	// If the config is not modified at all, (nil, ErrNotModified) as a quick response is allowed.
	LoadConfig(currentConfig map[string]ConfigValue) (map[string]ConfigValue, error)
}

ConfigProvider should implement the logic of loading config from somewhere, for example, a local file, or a remote config center

type ConfigSerializer

type ConfigSerializer interface {
	Encode(config map[string]ConfigValue) ([]byte, error)
}

ConfigSerializer is an interface that defines methods for serializing and deserializing configuration data.

type ConfigValue

type ConfigValue interface {
	DeepCopy() ConfigValue
	EqualsTo(ConfigValue) bool
	GetItem(itemType ItemType) (ConfigValueItem, error)
	GetItemOrDefault(itemType ItemType, defaultItem ConfigValueItem) ConfigValueItem
}

ConfigValue is business related, and config manager don't care about its content.

type ConfigValueItem

type ConfigValueItem interface {
	DeepCopy() ConfigValueItem
	EqualsTo(ConfigValueItem) bool
}

ConfigValueItem interface represents an item in a configuration value

type ItemInitializer

type ItemInitializer func([]byte) (ConfigValueItem, error)

ItemInitializer defines a function that takes in a byte slice and returns a ConfigValueItem and an error.

type ItemType

type ItemType string

ItemType is the type of unique identifier for ConfigValueItem

type Limiter

type Limiter interface {
	Allow() bool
}

Limiter is an interface that defines methods for limiting the rate of actions.

type LogFunc

type LogFunc func(format string, args ...interface{})

LogFunc is used to decouple config manager with logger implementations

type RefreshCompleteSignal

type RefreshCompleteSignal = chan error

RefreshCompleteSignal receives a signal when the refresh is done.

Jump to

Keyboard shortcuts

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