config

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 8 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	KeyPath Key
	Deleted bool
}

Change represents a change to a configuration key. When the Key has been deleted, Deleted is set to true.

type Config

type Config struct {
	PersistenceContext any
	// this is needed for the RetryWatcher that operates on ListResourceVersions and needs an initial starting point
	InitialListResourceVersion string
	// contains filtered or unexported fields
}

Config represents a general configuration with entries and change history. PersistenceContext is used by a repository to detect conflicts due to remote changes.

func CreateConfig

func CreateConfig(data Entries, options ...ConfigOption) Config

CreateConfig creates a new configuration with the provided entries.

func (Config) Delete

func (c Config) Delete(k Key) Config

Delete removes the configuration Key and Value. Returns a new Config with the Key deleted.

func (Config) DeleteAll

func (c Config) DeleteAll() Config

DeleteAll removes all key values pairs for the configuration. Returns a new empty Config with a change history containing all keys that haven been deleted.

func (Config) DeleteRecursive

func (c Config) DeleteRecursive(k Key) Config

DeleteRecursive removes all configuration for the given Key, including all configuration for sub-keys. Returns a new Config with without given Key.

func (Config) Diff

func (c Config) Diff(other Config) []DiffResult

Diff returns a list of DiffResult with all values that differs for a given key.

func (Config) Get

func (c Config) Get(k Key) (Value, bool)

Get returns the configuration value for the given key. When the key does not exist false is returned.

func (Config) GetAll

func (c Config) GetAll() Entries

GetAll returns a map of all Key-Value-pairs

func (Config) GetChangeHistory

func (c Config) GetChangeHistory() []Change

GetChangeHistory returns a slice of all changes made to the configuration.

func (Config) Set

func (c Config) Set(k Key, v Value) (Config, error)

Set sets the value for the given key in the configuration. Returns a new Config with the value set. Returns an error if the key is invalid or conflicts with existing keys.

type ConfigOption

type ConfigOption func(config *Config)

func WithInitialListResourceVersion added in v0.3.1

func WithInitialListResourceVersion(resourceVersion string) ConfigOption

WithInitialListResourceVersion adds the resourceVersion of the list containing the config. It's main use case is for the Config-Watches that operate on lists instead of single objects.

func WithPersistenceContext

func WithPersistenceContext(pCtx any) ConfigOption

type Converter

type Converter interface {
	Read(reader io.Reader) (Entries, error)
	Write(writer io.Writer, cfgData Entries) error
}

type DiffResult

type DiffResult struct {
	Key        Key
	Value      OptionalValue
	OtherValue OptionalValue
}

DiffResult represents a result of a configuration comparison.

type DoguConfig

type DoguConfig struct {
	DoguName dogu.SimpleName
	Config
}

DoguConfig represents a Dogu-specific configuration.

func CreateDoguConfig

func CreateDoguConfig(dogu dogu.SimpleName, e Entries) DoguConfig

CreateDoguConfig creates a new Dogu-specific configuration with the provided Dogu name and entries.

type Entries

type Entries map[Key]Value

Entries represents a map of configuration keys and values.

func MapToEntries added in v0.2.2

func MapToEntries(inputMap map[string]any) (Entries, error)

type GlobalConfig

type GlobalConfig struct {
	Config
}

GlobalConfig represents a global configuration.

func CreateGlobalConfig

func CreateGlobalConfig(e Entries) GlobalConfig

CreateGlobalConfig creates a new global configuration with the provided entries.

type Key

type Key string

Key represents a configuration key as a string.

func (Key) String

func (k Key) String() string

String returns the string representation of the Key.

type OptionalValue

type OptionalValue struct {
	String string
	Exists bool // Exists is true if String is not NULL
}

OptionalValue represents a configuration value as a string that may be null.

type Value

type Value string

Value represents a configuration value as a string.

func (Value) String

func (v Value) String() string

String returns the string representation of the Value.

type WatchFilter

type WatchFilter func([]DiffResult) bool

WatchFilter can be applied to the result of a comparison of two configurations. It is a predicate function that should to return true in case the filter matches.

func DirectoryFilter

func DirectoryFilter(directory Key) WatchFilter

DirectoryFilter is a WatchFilter to watch for changes for a directory. This can encompass multiple keys with the same prefix. For example: Filter with Key "key1/" watch for changes for the keys: key1/key2/key3 key1/key2/key3 ...

func KeyFilter

func KeyFilter(k Key) WatchFilter

KeyFilter is a WatchFilter to watch for changes for a single Key.

type YamlConverter

type YamlConverter struct {
}

func (*YamlConverter) Read

func (yc *YamlConverter) Read(reader io.Reader) (Entries, error)

func (*YamlConverter) Write

func (yc *YamlConverter) Write(writer io.Writer, cfgData Entries) error

Jump to

Keyboard shortcuts

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