Documentation ¶
Index ¶
- Constants
- type ConfigManager
- func (m *ConfigManager) DeregisterConfigChangeListener(identifier string)
- func (m *ConfigManager) Dump(filepath string) error
- func (m *ConfigManager) GetAllConfig() map[string]iface.ConfigValue
- func (m *ConfigManager) GetConfig(key string) (iface.ConfigValue, error)
- func (m *ConfigManager) GetConfigItem(key string, itemType iface.ItemType) (iface.ConfigValueItem, error)
- func (m *ConfigManager) GetProvider() iface.ConfigProvider
- func (m *ConfigManager) Refresh() iface.RefreshCompleteSignal
- func (m *ConfigManager) RefreshAndWait() error
- func (m *ConfigManager) RegisterConfigChangeListener(identifier string, listener iface.ConfigChangeListener)
- func (m *ConfigManager) Stop()
- type ConfigManagerOption
- func WithConfigProvider(provider iface.ConfigProvider) ConfigManagerOption
- func WithConfigSerializer(serializer iface.ConfigSerializer) ConfigManagerOption
- func WithErrorLogger(logger iface.LogFunc) ConfigManagerOption
- func WithLogLimiter(limiter iface.Limiter) ConfigManagerOption
- func WithRefreshInterval(interval time.Duration) ConfigManagerOption
- func WithWaitTimeout(timeout time.Duration) ConfigManagerOption
Constants ¶
const ( Name = "ConfigManager" Version = "v0.2.2" Home = "https://github.com/cloudwego/configmanager" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager is a struct that manages configuration data, including refreshing it at regular intervals. It uses a read-only sync.Map to store the current configuration, and provides methods for accessing it.
func NewConfigManager ¶
func NewConfigManager(options []ConfigManagerOption) *ConfigManager
NewConfigManager creates a new instance of ConfigManager with the given options.
func (*ConfigManager) DeregisterConfigChangeListener ¶
func (m *ConfigManager) DeregisterConfigChangeListener(identifier string)
DeregisterConfigChangeListener removes a listener from config manager
func (*ConfigManager) Dump ¶
func (m *ConfigManager) Dump(filepath string) error
Dump exports the ConfigManager's configuration to a file specified by the file path.
func (*ConfigManager) GetAllConfig ¶
func (m *ConfigManager) GetAllConfig() map[string]iface.ConfigValue
GetAllConfig retrieves all configuration values stored in the ConfigManager's map and returns it in a map with a string key and iface.ConfigValue value. **DO NOT MODIFY** values in the returned map.
func (*ConfigManager) GetConfig ¶
func (m *ConfigManager) GetConfig(key string) (iface.ConfigValue, error)
GetConfig retrieves the configuration value for the given key from the ConfigManager. If the key is not found, it returns an error indicating the key was not found. If the value of the key is not of type ConfigValue, it panics with an error message.
func (*ConfigManager) GetConfigItem ¶
func (m *ConfigManager) GetConfigItem(key string, itemType iface.ItemType) (iface.ConfigValueItem, error)
GetConfigItem retrieves a specific value from the configuration based on the given key and item type. Returns the retrieved configuration value item and an error if unable to retrieve it.
func (*ConfigManager) GetProvider ¶
func (m *ConfigManager) GetProvider() iface.ConfigProvider
GetProvider returns the ConfigProvider interface associated with the ConfigManager instance. In some scenarios, there's need to call the provider's API
func (*ConfigManager) Refresh ¶
func (m *ConfigManager) Refresh() iface.RefreshCompleteSignal
Refresh is called to refresh the configuration manager by sending a refresh signal. It may block if there are lots of callers
func (*ConfigManager) RefreshAndWait ¶
func (m *ConfigManager) RefreshAndWait() error
RefreshAndWait updates the configuration of ConfigManager and waits until the update process completes.
func (*ConfigManager) RegisterConfigChangeListener ¶
func (m *ConfigManager) RegisterConfigChangeListener(identifier string, listener iface.ConfigChangeListener)
RegisterConfigChangeListener registers a listener to config manager with a unique identifier for deregistration
func (*ConfigManager) Stop ¶
func (m *ConfigManager) Stop()
Stop ends the ConfigManager's refreshConfigLoop
type ConfigManagerOption ¶
type ConfigManagerOption func(*ConfigManager)
ConfigManagerOption is a function type that modifies the configuration of a ConfigManager
func WithConfigProvider ¶
func WithConfigProvider(provider iface.ConfigProvider) ConfigManagerOption
WithConfigProvider sets the given ConfigProvider as the source for configuration data.
func WithConfigSerializer ¶
func WithConfigSerializer(serializer iface.ConfigSerializer) ConfigManagerOption
WithConfigSerializer sets the ConfigSerializer for the ConfigManager. If not set, the serializer defaults to be util.JSONSerializer
func WithErrorLogger ¶
func WithErrorLogger(logger iface.LogFunc) ConfigManagerOption
WithErrorLogger sets the error logger for the ConfigManager instance If not set, the logger defaults to be log.Printf
func WithLogLimiter ¶
func WithLogLimiter(limiter iface.Limiter) ConfigManagerOption
WithLogLimiter sets a Limiter for logging in ConfigManager.
func WithRefreshInterval ¶
func WithRefreshInterval(interval time.Duration) ConfigManagerOption
WithRefreshInterval sets the interval time for refreshing the configuration. If not set, the interval defaults to be defaultRefreshInterval
func WithWaitTimeout ¶
func WithWaitTimeout(timeout time.Duration) ConfigManagerOption
WithWaitTimeout sets the timeout for waiting for the configuration update to complete. if not set, the timeout defaults to be defaultWaitTimeout