source

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package source manage all the config source and merge configs by precedence

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotExist   = errors.New("key does not exist")
	ErrIgnoreChange  = errors.New("ignore key changed")
	ErrWriterInvalid = errors.New("writer is invalid")
)

errors.

Functions

This section is empty.

Types

type ConfigSource

type ConfigSource interface {
	Set(key string, value interface{}) error
	Delete(key string) error
	GetConfigurations() (map[string]interface{}, error)
	GetConfigurationByKey(string) (interface{}, error)
	Watch(EventHandler) error
	GetPriority() int
	SetPriority(priority int)
	Cleanup() error
	GetSourceName() string

	AddDimensionInfo(labels map[string]string) error
}

ConfigSource get key values from a system, like file system, key value store, memory etc.

type EventHandler

type EventHandler interface {
	OnEvent(event *event.Event)
	OnModuleEvent(events []*event.Event)
}

EventHandler handles config change event.

type Manager

type Manager struct {
	Sources map[string]ConfigSource

	ConfigurationMap sync.Map
	// contains filtered or unexported fields
}

Manager manage all sources and config from them.

func NewManager

func NewManager() *Manager

NewManager creates an object of Manager.

func (*Manager) AddDimensionInfo

func (m *Manager) AddDimensionInfo(labels map[string]string) (map[string]string, error)

AddDimensionInfo adds the dimensionInfo to the list of which configurations needs to be pulled.

func (*Manager) AddSource

func (m *Manager) AddSource(source ConfigSource) error

AddSource adds a source to configurationManager.

func (*Manager) Cleanup

func (m *Manager) Cleanup() error

Cleanup close and cleanup config manager channel.

func (*Manager) Configs

func (m *Manager) Configs() map[string]interface{}

Configs returns all the key values.

func (*Manager) ConfigsWithSourceNames

func (m *Manager) ConfigsWithSourceNames() map[string]interface{}

ConfigsWithSourceNames returns all the key values along with its source name the returned map will be like:

map[string]interface{}{
		key string: map[string]interface{"value": value, "source": sourceName}
}

func (*Manager) Delete

func (m *Manager) Delete(k string) error

Delete call Delete of all sources.

func (*Manager) GetConfig

func (m *Manager) GetConfig(key string) interface{}

GetConfig returns the value for a particular key from cache.

func (*Manager) IsKeyExist

func (m *Manager) IsKeyExist(key string) bool

IsKeyExist check if key exist in cache.

func (*Manager) Marshal

func (m *Manager) Marshal(w io.Writer) error

Marshal function is used to write all configuration by yaml.

func (*Manager) OnEvent

func (m *Manager) OnEvent(event *event.Event)

OnEvent Triggers actions when an event is generated.

func (*Manager) OnModuleEvent

func (m *Manager) OnModuleEvent(event []*event.Event)

OnModuleEvent Triggers actions when events are generated.

func (*Manager) Refresh

func (m *Manager) Refresh(sourceName string) error

Refresh reload the configurations of a source.

func (*Manager) RegisterListener

func (m *Manager) RegisterListener(listenerObj event.Listener, keys ...string) error

RegisterListener Function to Register all listener for different key changes.

func (*Manager) RegisterModuleListener

func (m *Manager) RegisterModuleListener(listenerObj event.ModuleListener, prefixes ...string) error

RegisterModuleListener Function to Register all moduleListener for different key(prefix) changes.

func (*Manager) Set

func (m *Manager) Set(k string, v interface{}) error

Set call set of all sources.

func (*Manager) UnRegisterListener

func (m *Manager) UnRegisterListener(listenerObj event.Listener, keys ...string) error

UnRegisterListener remove listener.

func (*Manager) UnRegisterModuleListener

func (m *Manager) UnRegisterModuleListener(listenerObj event.ModuleListener, prefixes ...string) error

UnRegisterModuleListener remove moduleListener.

func (*Manager) Unmarshal

func (m *Manager) Unmarshal(obj interface{}) error

Unmarshal function is used in the case when user want his yaml file to be unmarshalled to structure pointer Unmarshal function accepts a pointer and in called function anyone can able to get the data in passed object Unmarshal only accepts a pointer values Unmarshal returns error if obj values are 0. nil and value type. Procedure:

  1. Unmarshal first checks the passed object type using reflection.
  2. Based on type Unmarshal function will check and set the values ex: If type is basic types like int, string, float then it will assigb directly values, If type is map, ptr and struct then it will again send for unmarshal until it find the basic type and set the values

Directories

Path Synopsis
Package cli created on 2017/6/22.
Package cli created on 2017/6/22.
Package env created on 2017/6/22.
Package env created on 2017/6/22.
Package filesource created on 2017/6/22.
Package filesource created on 2017/6/22.
kie

Jump to

Keyboard shortcuts

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