config

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: GPL-3.0 Imports: 24 Imported by: 8

Documentation

Overview

Package config provides a versatile configuration management system.

Package config ... (linter fix)

Package config ... (linter fix)

Index

Constants

View Source
const (
	ExpertiseLevelUser      uint8 = 0
	ExpertiseLevelExpert    uint8 = 1
	ExpertiseLevelDeveloper uint8 = 2

	ExpertiseLevelNameUser      = "user"
	ExpertiseLevelNameExpert    = "expert"
	ExpertiseLevelNameDeveloper = "developer"
)

Expertise Level constants

View Source
const (
	OptTypeString      uint8 = 1
	OptTypeStringArray uint8 = 2
	OptTypeInt         uint8 = 3
	OptTypeBool        uint8 = 4
)

Various attribute options. Use ExternalOptType for extended types in the frontend.

View Source
const (
	ReleaseLevelStable       uint8 = 0
	ReleaseLevelBeta         uint8 = 1
	ReleaseLevelExperimental uint8 = 2

	ReleaseLevelNameStable       = "stable"
	ReleaseLevelNameBeta         = "beta"
	ReleaseLevelNameExperimental = "experimental"
)

Release Level constants

Variables

View Source
var (
	// ErrInvalidJSON is returned by SetConfig and SetDefaultConfig if they receive invalid json.
	ErrInvalidJSON = errors.New("json string invalid")

	// ErrInvalidOptionType is returned by SetConfigOption and SetDefaultConfigOption if given an unsupported option type.
	ErrInvalidOptionType = errors.New("invalid option value type")
)
View Source
var (
	// Concurrent makes concurrency safe get methods available.
	Concurrent = &safe{}
)

Functions

func CleanFlattenedConfig added in v0.5.1

func CleanFlattenedConfig(flattenedConfig map[string]interface{})

CleanFlattenedConfig removes all inexistent configuration options from the given flattened config map.

func CleanHierarchicalConfig added in v0.5.1

func CleanHierarchicalConfig(config map[string]interface{})

CleanHierarchicalConfig removes all inexistent configuration options from the given hierarchical config map.

func Expand added in v0.5.1

func Expand(flattenedConfig map[string]interface{}) (config map[string]interface{})

Expand returns a hierarchical copy of the given flattened config.

func Flatten added in v0.5.1

func Flatten(config map[string]interface{}) (flattenedConfig map[string]interface{})

Flatten returns a flattened copy of the given hierarchical config.

func GetExpertiseLevel added in v0.4.0

func GetExpertiseLevel() uint8

GetExpertiseLevel returns the current active expertise level.

func JSONToMap

func JSONToMap(jsonData []byte) (map[string]interface{}, error)

JSONToMap parses and flattens a hierarchical json object.

func MapToJSON

func MapToJSON(config map[string]interface{}) ([]byte, error)

MapToJSON expands a flattened map and returns it as json.

func PutValueIntoHierarchicalConfig added in v0.5.1

func PutValueIntoHierarchicalConfig(config map[string]interface{}, key string, value interface{})

PutValueIntoHierarchicalConfig injects a configuration entry into an hierarchical config map. Conflicting entries will be replaced.

func Register

func Register(option *Option) error

Register registers a new configuration option.

func SetConfigOption

func SetConfigOption(key string, value interface{}) error

SetConfigOption sets a single value in the (prioritized) user defined config.

func SetDataRoot added in v0.3.0

func SetDataRoot(root *utils.DirStructure)

SetDataRoot sets the data root from which the updates module derives its paths.

func SetDefaultConfig

func SetDefaultConfig(newValues map[string]interface{}) error

SetDefaultConfig sets the (fallback) default config.

func SetDefaultConfigOption

func SetDefaultConfigOption(key string, value interface{}) error

SetDefaultConfigOption sets a single value in the (fallback) default config.

Types

type BoolOption

type BoolOption func() bool

BoolOption defines the returned function by GetAsBool.

func GetAsBool

func GetAsBool(name string, fallback bool) BoolOption

GetAsBool returns a function that returns the wanted int with high performance.

type IntOption

type IntOption func() int64

IntOption defines the returned function by GetAsInt.

func GetAsInt

func GetAsInt(name string, fallback int64) IntOption

GetAsInt returns a function that returns the wanted int with high performance.

type Option

type Option struct {
	sync.Mutex

	Name        string
	Key         string // in path format: category/sub/key
	Description string
	Help        string
	Order       int

	OptType        uint8
	ExpertiseLevel uint8
	ReleaseLevel   uint8

	RequiresRestart bool
	DefaultValue    interface{}

	ExternalOptType string
	ValidationRegex string
	// contains filtered or unexported fields
}

Option describes a configuration option.

func (*Option) Export

func (option *Option) Export() (record.Record, error)

Export expors an option to a Record.

type Perspective added in v0.5.0

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

Perspective is a view on configuration data without interfering with the configuration system.

func NewPerspective added in v0.5.0

func NewPerspective(config map[string]interface{}) (*Perspective, error)

NewPerspective parses the given config and returns it as a new perspective.

func (*Perspective) GetAsBool added in v0.5.0

func (p *Perspective) GetAsBool(name string) (value bool, ok bool)

GetAsBool returns a function that returns the wanted int with high performance.

func (*Perspective) GetAsInt added in v0.5.0

func (p *Perspective) GetAsInt(name string) (value int64, ok bool)

GetAsInt returns a function that returns the wanted int with high performance.

func (*Perspective) GetAsString added in v0.5.0

func (p *Perspective) GetAsString(name string) (value string, ok bool)

GetAsString returns a function that returns the wanted string with high performance.

func (*Perspective) GetAsStringArray added in v0.5.0

func (p *Perspective) GetAsStringArray(name string) (value []string, ok bool)

GetAsStringArray returns a function that returns the wanted string with high performance.

type StorageInterface added in v0.3.0

type StorageInterface struct {
	storage.InjectBase
}

StorageInterface provices a storage.Interface to the configuration manager.

func (*StorageInterface) Delete added in v0.3.0

func (s *StorageInterface) Delete(key string) error

Delete deletes a record from the database.

func (*StorageInterface) Get added in v0.3.0

func (s *StorageInterface) Get(key string) (record.Record, error)

Get returns a database record.

func (*StorageInterface) Put added in v0.3.0

Put stores a record in the database.

func (*StorageInterface) Query added in v0.3.0

func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error)

Query returns a an iterator for the supplied query.

func (*StorageInterface) ReadOnly added in v0.3.0

func (s *StorageInterface) ReadOnly() bool

ReadOnly returns whether the database is read only.

type StringArrayOption

type StringArrayOption func() []string

StringArrayOption defines the returned function by GetAsStringArray.

func GetAsStringArray

func GetAsStringArray(name string, fallback []string) StringArrayOption

GetAsStringArray returns a function that returns the wanted string with high performance.

type StringOption

type StringOption func() string

StringOption defines the returned function by GetAsString.

func GetAsString

func GetAsString(name string, fallback string) StringOption

GetAsString returns a function that returns the wanted string with high performance.

type ValidityFlag added in v0.5.0

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

ValidityFlag is a flag that signifies if the configuration has been changed. It is not safe for concurrent use.

func NewValidityFlag added in v0.5.0

func NewValidityFlag() *ValidityFlag

NewValidityFlag returns a flag that signifies if the configuration has been changed.

func (*ValidityFlag) IsValid added in v0.5.0

func (vf *ValidityFlag) IsValid() bool

IsValid returns if the configuration is still valid.

func (*ValidityFlag) Refresh added in v0.5.0

func (vf *ValidityFlag) Refresh()

Refresh refreshes the flag and makes it reusable.

Jump to

Keyboard shortcuts

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