config

package
v0.0.0-...-ed39d5d Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	Parse(path string) error
	GetOption(name string) (*Option, error)
}

Config interface for methods to accept various types of config objects (INI/JSON/...)

type INIConfig

type INIConfig struct {
	WithConfigBase
}

INIConfig holds complete configuration data and metadata for configuration saved as INI file.

func NewINIConfig

func NewINIConfig(metadata map[string][]Parameter, logger *logging.Logger) *INIConfig

NewINIConfig creates and initializes new INIConfig object according to given metadata

func (INIConfig) GetOption

func (conf INIConfig) GetOption(name string) (*Option, error)

GetOption returns Option objects according to given "section-name/option-name" string.

func (INIConfig) Parse

func (conf INIConfig) Parse(path string) error

Parse loads data from given file

type JSONConfig

type JSONConfig struct {
	WithConfigBase
	// contains filtered or unexported fields
}

JSONConfig holds complete configuration data and metadata for configuration saved as JSON file.

func NewJSONConfig

func NewJSONConfig(metadata map[string][]Parameter, logger *logging.Logger) *JSONConfig

NewJSONConfig creates and initializes new config object according to given metadata.

func (*JSONConfig) AddStructured

func (conf *JSONConfig) AddStructured(section, name, tag string, object interface{})

AddStructured can be used when config values are structured deeper than section/parameter. Note that structured parameters are missing validation logic other than through standard json module (can be changed in future)

func (JSONConfig) GetOption

func (conf JSONConfig) GetOption(name string) (*Option, error)

GetOption returns Option objects according to given "section.option[.sub-option[.sub-option]]" string.

func (JSONConfig) Parse

func (conf JSONConfig) Parse(path string) error

Parse loads data from given file

func (JSONConfig) ParseBytes

func (conf JSONConfig) ParseBytes(data []byte) error

Parse loads data from given byte slice

type Option

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

Option holds single value of single configuration option.

func (*Option) GetBool

func (opt *Option) GetBool() bool

GetBool returns option value as bool.

func (*Option) GetBytes

func (opt *Option) GetBytes() []byte

GetBytes returns option value as slice of bytes.

func (*Option) GetFloat

func (opt *Option) GetFloat() float64

GetFLoat returns option value as float.

func (*Option) GetInt

func (opt *Option) GetInt() int64

GetInt returns option value as int.

func (*Option) GetInts

func (opt *Option) GetInts(separator string) []int

GetInts returns option value as slice of ints. Use this for value in form of <separator> separated list of ints.

func (*Option) GetString

func (opt *Option) GetString() string

GetString returns option value as string.

func (*Option) GetStrings

func (opt *Option) GetStrings(separator string) []string

GetStrings returns option value as slice of strings. Use this for value in form of <separator> separated list of strings.

func (*Option) GetStructured

func (opt *Option) GetStructured() interface{}

type Parameter

type Parameter struct {
	Name       string
	Tag        string
	Default    interface{}
	Validators []Validator
}

Parameter holds metadata and validators for the single configuration option.

type Section

type Section struct {
	Options map[string]*Option
}

Section holds configuration for appropriate section in config file.

type Validator

type Validator func(interface{}) (interface{}, error)

Validator checks the validity of the config option value. It accepts single value and returns nil (and corrected value if possible) if the value is valid or appropriate error otherwise.

func BoolValidatorFactory

func BoolValidatorFactory() Validator

BoolValidatorFactory creates validator for checking if the validator's given value is bool.

func IntValidatorFactory

func IntValidatorFactory() Validator

IntValidatorFactory creates validator for checking if the validator's given value is int.

func MultiIntValidatorFactory

func MultiIntValidatorFactory(separator string) Validator

MultiIntValidatorFactory creates validator for checking if the validator's given value is list of ints separated by given separator

func StringOptionsValidatorFactory

func StringOptionsValidatorFactory(options []string) Validator

StringOptionsValidatorFactory creates validator for checking if the validator's given value is one of the factory's given string options.

type WithConfigBase

type WithConfigBase struct {
	Sections map[string]*Section
	// contains filtered or unexported fields
}

WithConfigBase holds config metadata and logger

func (*WithConfigBase) GetMetadata

func (base *WithConfigBase) GetMetadata() map[string][]Parameter

GetMetadata returns config metadata

Jump to

Keyboard shortcuts

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