config

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	CONFIG_TREE_SEPARATOR = "/"
	KEY_ALLOWED_CHARS     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
)
View Source
const (
	ENV_SPLIT_CHAR = "_"
	ENTRY_SPLIT    = "="
)

Variables

View Source
var (
	ErrDumpFailed     = errors.New("dump failed")
	ErrMergeFailed    = errors.New("merge failed")
	ErrConfigKey      = errors.New("config key error")
	ErrTypeMismatch   = errors.New("type mismatch")
	ErrCopyConfig     = errors.New("copy config error")
	ErrNoConfigSource = errors.New("no config source provided")
	ErrLoadingConfig  = errors.New("loading config failed")
	ErrValueInvalid   = errors.New("value invalid")
)

Functions

func IsValidKey added in v0.1.6

func IsValidKey(raw_key string) error

Types

type Config

type Config struct {
	ConfigStore
	// contains filtered or unexported fields
}

func New added in v0.1.4

func New(ctx context.Context) (*Config, error)

func NewLoadedConfig added in v0.1.6

func NewLoadedConfig(ctx context.Context, envPrefixList []string, fileList []string) (*Config, error)

func WithInitialValues added in v0.1.6

func WithInitialValues(ctx context.Context, initialValues map[string]interface{}) (*Config, error)

func WithInitialValuesAndOptions added in v0.1.6

func WithInitialValuesAndOptions(ctx context.Context, initialValues map[string]interface{}, options *Config) (*Config, error)

func (*Config) Compare

func (c *Config) Compare(ctx context.Context, cmp *Config, valueCompare bool) error

check if base config has all keys defined in cmp if firstError is true, return first error encountered

func (*Config) CompareMap added in v0.1.6

func (c *Config) CompareMap(ctx context.Context, cmpMap map[string]string, valueCompare bool) error

check if base config has all keys defined in cmp if firstError is true, return first error encountered

func (*Config) Copy

func (c *Config) Copy(ctx context.Context) (*Config, error)

func (*Config) DumpToFile

func (c *Config) DumpToFile(ctx context.Context, format string, outFile string) error

func (*Config) GetConfig

func (c *Config) GetConfig(ctx context.Context, key string) (*Config, error)

func (*Config) Load added in v0.1.6

func (c *Config) Load(ctx context.Context, envPrefixList []string, fileList []string) error

func (*Config) Merge

func (c *Config) Merge(ctx context.Context, merger ConfigStore, overwrite bool) error

func (*Config) MergeIn added in v0.1.6

func (c *Config) MergeIn(ctx context.Context, baseKey string, value ConfigStore, force bool) error

func (*Config) Sprint

func (c *Config) Sprint() string

type ConfigLoader added in v0.1.4

type ConfigLoader struct{}

func (*ConfigLoader) LoadEnv added in v0.1.4

func (cl *ConfigLoader) LoadEnv(ctx context.Context, store ConfigStore, prefixList []string) error

func (*ConfigLoader) LoadFile added in v0.1.4

func (cl *ConfigLoader) LoadFile(ctx context.Context, store ConfigStore, filePaths []string) error

type ConfigStore

type ConfigStore interface {
	Get(ctx context.Context, key string) (string, error)
	GetAll(ctx context.Context, key string) map[string]string
	Set(ctx context.Context, key string, value string, force bool) error
	Has(ctx context.Context, key string) bool
	// HasAllKeys(cmp map[string]interface{}) error
	Keys(ctx context.Context) []string
}

func NewConfigStore added in v0.1.6

func NewConfigStore(ctx context.Context) (ConfigStore, error)

type ConfigStoreImpl added in v0.1.6

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

type ConfigStoreImpl map[string]interface{}

func (*ConfigStoreImpl) Get added in v0.1.6

func (c *ConfigStoreImpl) Get(ctx context.Context, key string) (string, error)

func (*ConfigStoreImpl) GetAll added in v0.1.6

func (c *ConfigStoreImpl) GetAll(ctx context.Context, key string) map[string]string

GetAll returns all values that match the given key. If the key is not found, nil is returned. // If the key is found, but no values match, an empty map is returned. If the key is found, and values match, a map of values is returned, index by the key suffix (the part of the key after the last CONFIG_TREE_SEPARATOR) Single values are therefore indexed by an empty string.

func (*ConfigStoreImpl) Has added in v0.1.6

func (c *ConfigStoreImpl) Has(ctx context.Context, key string) bool

func (*ConfigStoreImpl) HasAllKeys added in v0.1.6

func (c *ConfigStoreImpl) HasAllKeys(ctx context.Context, cmp []string) error

func (*ConfigStoreImpl) Keys added in v0.1.6

func (c *ConfigStoreImpl) Keys(ctx context.Context) []string

func (*ConfigStoreImpl) Set added in v0.1.6

func (c *ConfigStoreImpl) Set(ctx context.Context, key string, value string, force bool) error

type ConfigStoreNew added in v0.1.6

type ConfigStoreNew func(context.Context) (ConfigStore, error)
var DefaultConfigStore ConfigStoreNew = NewConfigStore

type ErrCopyConfigReason added in v0.1.6

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

func (ErrCopyConfigReason) Error added in v0.1.6

func (e ErrCopyConfigReason) Error() string

func (ErrCopyConfigReason) Unwrap added in v0.1.6

func (e ErrCopyConfigReason) Unwrap() error

type ErrDumpToFile

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

func (*ErrDumpToFile) Error

func (c *ErrDumpToFile) Error() string

func (*ErrDumpToFile) Unwrap

func (c *ErrDumpToFile) Unwrap() error

type ErrFieldNotBool

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

func (*ErrFieldNotBool) Error

func (f *ErrFieldNotBool) Error() string

func (*ErrFieldNotBool) Unwrap

func (f *ErrFieldNotBool) Unwrap() error

type ErrFieldNotConfig

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

func (*ErrFieldNotConfig) Error

func (f *ErrFieldNotConfig) Error() string

func (*ErrFieldNotConfig) Unwrap

func (f *ErrFieldNotConfig) Unwrap() error

type ErrFieldNotDuration

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

func (*ErrFieldNotDuration) Error

func (f *ErrFieldNotDuration) Error() string

func (*ErrFieldNotDuration) Unwrap

func (f *ErrFieldNotDuration) Unwrap() error

type ErrFieldNotFloat

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

func (*ErrFieldNotFloat) Error

func (f *ErrFieldNotFloat) Error() string

func (*ErrFieldNotFloat) Unwrap

func (f *ErrFieldNotFloat) Unwrap() error

type ErrFieldNotInt

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

func (*ErrFieldNotInt) Error

func (f *ErrFieldNotInt) Error() string

func (*ErrFieldNotInt) Unwrap

func (f *ErrFieldNotInt) Unwrap() error

type ErrFieldNotString

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

func (*ErrFieldNotString) Error

func (f *ErrFieldNotString) Error() string

func (*ErrFieldNotString) Unwrap

func (f *ErrFieldNotString) Unwrap() error

type ErrKeyAmbiguous added in v0.1.6

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

func (*ErrKeyAmbiguous) Error added in v0.1.6

func (e *ErrKeyAmbiguous) Error() string

func (*ErrKeyAmbiguous) Unwrap added in v0.1.6

func (e *ErrKeyAmbiguous) Unwrap() error

type ErrKeyInStore

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

func (*ErrKeyInStore) Error

func (k *ErrKeyInStore) Error() string

func (*ErrKeyInStore) Unwrap added in v0.1.6

func (k *ErrKeyInStore) Unwrap() error

type ErrKeyNotFound

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

func (*ErrKeyNotFound) Error

func (k *ErrKeyNotFound) Error() string

func (*ErrKeyNotFound) Unwrap

func (k *ErrKeyNotFound) Unwrap() error

type ErrKeyValueInvalid added in v0.1.6

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

func (*ErrKeyValueInvalid) Error added in v0.1.6

func (v *ErrKeyValueInvalid) Error() string

func (*ErrKeyValueInvalid) Unwrap added in v0.1.6

func (v *ErrKeyValueInvalid) Unwrap() error

func (*ErrKeyValueInvalid) Wrap added in v0.1.6

func (v *ErrKeyValueInvalid) Wrap(err error)

type ErrMergeConfigReason added in v0.1.6

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

func (ErrMergeConfigReason) Error added in v0.1.6

func (e ErrMergeConfigReason) Error() string

func (ErrMergeConfigReason) Unwrap added in v0.1.6

func (e ErrMergeConfigReason) Unwrap() error

type ErrParsingEnvVar added in v0.1.6

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

func (*ErrParsingEnvVar) Error added in v0.1.6

func (e *ErrParsingEnvVar) Error() string

func (*ErrParsingEnvVar) Unwrap added in v0.1.6

func (e *ErrParsingEnvVar) Unwrap() error

type ErrValueMismatch

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

func (*ErrValueMismatch) Error

func (v *ErrValueMismatch) Error() string

func (*ErrValueMismatch) Unwrap

func (v *ErrValueMismatch) Unwrap() error

type ErrValueNotFound

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

func (*ErrValueNotFound) Error

func (v *ErrValueNotFound) Error() string

func (*ErrValueNotFound) Unwrap

func (v *ErrValueNotFound) Unwrap() error

type KeyCharInvalid

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

func (*KeyCharInvalid) Error

func (k *KeyCharInvalid) Error() string

func (*KeyCharInvalid) Unwrap

func (k *KeyCharInvalid) Unwrap() error

type Loader added in v0.1.6

type Loader interface {
	LoadEnv(ctx context.Context, store ConfigStore, prefixList []string) error
	LoadFile(ctx context.Context, store ConfigStore, paths []string) error
}

Jump to

Keyboard shortcuts

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