flexiconf

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 14 Imported by: 0

README

flexiconf

GO library for flexible configuration handling

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Downcase

func Downcase(values []string) (result []string)

func FilterByWildcard

func FilterByWildcard(patterns interface{}, list interface{}, ignore_case bool) (result []string)

func FormatParameter

func FormatParameter(section string, id string, parameter string) string

func FormatSection

func FormatSection(section string, id string) string

func Match

func Match(pattern string, text string) *[]string

func MatchWildcard

func MatchWildcard(patterns interface{}, list interface{}, ignore_case bool) bool

func NormalizeLine

func NormalizeLine(ctx *ParseContext, text string) (string, bool)

Normalize line by replacing tabs by spaces, trimming whitespace on both ends and removing comments

func ReplaceVariables

func ReplaceVariables(ctx *ParseContext, text string, definitions map[string]string) (newtext string, unreplaced []string)

func SplitColon

func SplitColon(ctx *ParseContext, text string) (string, string)

func SplitDefine

func SplitDefine(ctx *ParseContext, text string) (name string, value string, isDefine bool)

func SplitEqual

func SplitEqual(ctx *ParseContext, text string) (string, string)

func SplitSection

func SplitSection(ctx *ParseContext, text string) (name string, id string, isSection bool)

func SplitSpace

func SplitSpace(ctx *ParseContext, text string) (string, string)

func SplitSpaceOrEqual

func SplitSpaceOrEqual(ctx *ParseContext, text string) (string, string)

func SplitTag

func SplitTag(tag string) (section string, sid string, param string)

func SplitUndefine

func SplitUndefine(ctx *ParseContext, text string) (name string, isUndefine bool)

func Tokenize

func Tokenize(text string) (tokens []string)

func Unique

func Unique(list []string) (result []string)

func Upcase

func Upcase(values []string) (result []string)

Types

type Config

type Config struct {
	File             string
	Hash             string
	SectionList      []Section
	Warnings         []string
	Schema           *Config
	ValidationErrors []string

	Normalizer       NormalizerFunc       // function normalizing a line (trimming, removing comments, ...)
	Replacer         ReplacerFunc         // function replacing defined variables
	DefineSplitter   DefineSplitterFunc   // function splitting variable definition into key and value
	UndefineSplitter UndefineSplitterFunc // " same for undefining a variable
	SectionSplitter  SectionSplitterFunc  // function splitting a line into section and id
	KeyValSplitter   KeyValSplitterFunc   // function splitting a line into key and value

	Inherit          interface{}    // bool, string, []string, *regexp.Regexp, *[]regexp.Regexp
	BadNames         *regexp.Regexp // do not include resolved files matching this regexp
	GoodNames        *regexp.Regexp // only include resolved files matching this regexp
	PreferFirstValue bool           // if true, use the first value for single value expressions; overridden by schema

	RawSections map[string]interface{} // sections that should be treated as containing raw data

	Custom map[string]interface{} // custom settings
}

func Load

func Load(file string) (c *Config, err error)

Load creates a new Config structure, loads the given config file into it and returns a reference to the configuration data. An error is returned if the file could not be loaded. Parsing problems are logged in the structure's Warnings field.

func New

func New() *Config

New returns a reference to a newly created Config structure set up with default values.

func Parse

func Parse(text string, file string) (c *Config)

Parse creates a new Config structure, parses the given text into it and returns a reference to the configuration data. Parsing problems are logged in the structure's Warnings field.

func (*Config) AbsolutePath

func (c *Config) AbsolutePath(f string) string

func (*Config) All

func (c *Config) All(tag string) *Values

func (*Config) CanInherit

func (c *Config) CanInherit(tag string) bool

func (*Config) Dump

func (c *Config) Dump(with_source bool)

func (*Config) ErrMissing

func (c *Config) ErrMissing(section string) error

func (*Config) Error

func (c *Config) Error(v interface{}, args ...interface{}) error

func (*Config) First

func (c *Config) First(tag string) (v *Value)

func (*Config) FirstOrDefault

func (c *Config) FirstOrDefault(tag string, defval *Value) (v *Value)

func (*Config) Get

func (c *Config) Get(tag string) *Values

func (*Config) IsSet

func (c *Config) IsSet(tag string) bool

func (*Config) Last

func (c *Config) Last(tag string) (v *Value)

func (*Config) LastOrDefault

func (c *Config) LastOrDefault(tag string, defval *Value) (v *Value)

func (*Config) Load

func (c *Config) Load(file string) (err error)

Load and parse the given file into the configuration. An error is returned if the file could not be loaded. Parsing problems are logged in the structure's Warnings field.

func (*Config) One

func (c *Config) One(tag string) *Value

func (*Config) OneOrDefault

func (c *Config) OneOrDefault(tag string, defval *Value) *Value

func (*Config) Parameter

func (c *Config) Parameter(section string, id string, parameter string) *Parameter

func (*Config) Parse

func (c *Config) Parse(text string, file string)

Parse the given file into the configuration. Parsing problems are logged in the structure's Warnings field.

func (*Config) Section

func (c *Config) Section(section string, id string) *Section

func (*Config) SectionIds

func (c *Config) SectionIds(section string) (result []string)

func (*Config) SectionNames

func (c *Config) SectionNames() (result []string)

func (*Config) Sections

func (c *Config) Sections() *[]Section

func (*Config) SetSchema

func (c *Config) SetSchema(config *Config) error

func (*Config) String

func (c *Config) String(tag string) string

func (*Config) Strings

func (c *Config) Strings(tag string) (result []string)

func (*Config) Tokens

func (c *Config) Tokens(tag string, downcase bool) (tokens []string)

func (*Config) UniqueTokens

func (c *Config) UniqueTokens(tag string, downcase bool) (tokens []string)

func (*Config) Validate

func (c *Config) Validate() error

type DefineSplitterFunc

type DefineSplitterFunc func(*ParseContext, string) (string, string, bool)

type KeyValSplitterFunc

type KeyValSplitterFunc func(*ParseContext, string) (string, string)

type NormalizerFunc

type NormalizerFunc func(*ParseContext, string) (string, bool)

type Parameter

type Parameter struct {
	Name      string
	Source    Source
	ValueList Values

	Section *Section
}

func (*Parameter) Dump

func (p *Parameter) Dump(with_source bool)

func (Parameter) FindValues

func (p Parameter) FindValues() *Values

func (Parameter) First

func (p Parameter) First() (v *Value)

func (Parameter) FirstOrDefault

func (p Parameter) FirstOrDefault(defval *Value) (v *Value)

func (Parameter) Float32

func (p Parameter) Float32() (float32, bool)

func (Parameter) Float32OrDefault

func (p Parameter) Float32OrDefault(defval float32) float32

func (Parameter) Float64

func (p Parameter) Float64() (float64, bool)

func (Parameter) Float64OrDefault

func (p Parameter) Float64OrDefault(defval float64) float64

func (Parameter) Floats32

func (p Parameter) Floats32() []float32

func (Parameter) Floats64

func (p Parameter) Floats64() []float64

func (Parameter) IP

func (p Parameter) IP() net.IP

func (Parameter) IP4

func (p Parameter) IP4() net.IP

func (Parameter) IP4s

func (p Parameter) IP4s() (result []net.IP)

func (Parameter) IP6

func (p Parameter) IP6() net.IP

func (Parameter) IP6s

func (p Parameter) IP6s() (result []net.IP)

func (Parameter) IPs

func (p Parameter) IPs() (result []net.IP)

func (Parameter) Int

func (p Parameter) Int() (int, bool)

func (Parameter) Int32

func (p Parameter) Int32() (int32, bool)

func (Parameter) Int32OrDefault

func (p Parameter) Int32OrDefault(defval int32) int32

func (Parameter) Int64

func (p Parameter) Int64() (int64, bool)

func (Parameter) Int64OrDefault

func (p Parameter) Int64OrDefault(defval int64) int64

func (Parameter) IntOrDefault

func (p Parameter) IntOrDefault(defval int) int

func (Parameter) Interpreted

func (p Parameter) Interpreted() []string

func (Parameter) Ints

func (p Parameter) Ints() []int

func (Parameter) Ints32

func (p Parameter) Ints32() []int32

func (Parameter) Ints64

func (p Parameter) Ints64() []int64

func (Parameter) IsOff

func (p Parameter) IsOff() bool

func (Parameter) IsOn

func (p Parameter) IsOn() bool

func (Parameter) Last

func (p Parameter) Last() (v *Value)

func (Parameter) LastOrDefault

func (p Parameter) LastOrDefault(defval *Value) (v *Value)

func (Parameter) NonEmptyStringOrDefault

func (p Parameter) NonEmptyStringOrDefault(defval string) string

func (Parameter) Raw

func (p Parameter) Raw() []string

func (Parameter) String

func (p Parameter) String() string

func (Parameter) StringOrDefault

func (p Parameter) StringOrDefault(defval string) string

func (Parameter) Strings

func (p Parameter) Strings() []string

func (*Parameter) Tag

func (p *Parameter) Tag() string

func (Parameter) Tokens

func (p Parameter) Tokens(downcase bool) (tokens []string)

func (Parameter) Unique

func (p Parameter) Unique(ignorecase bool) (result Values)

func (Parameter) UniqueTokens

func (p Parameter) UniqueTokens(downcase bool) (tokens []string)

func (Parameter) Values

func (p Parameter) Values() *Values

type ParseContext

type ParseContext struct {
	Config     *Config
	TextFile   *textfile.File
	LineNumber int
}

type ReplacerFunc

type ReplacerFunc func(*ParseContext, string, map[string]string) (string, []string)

type Section

type Section struct {
	Name          string
	ID            string
	Source        Source
	ParameterList []Parameter
	Lines         []string
	ParameterSeq  []*Parameter

	Config *Config // Reference to parent Config
}

Section structure contains info about a section and its parameters

func (*Section) Dump

func (s *Section) Dump(with_source bool)

Dump prints the section config data in INI format

func (*Section) ErrID

func (s *Section) ErrID(p string) error

func (*Section) ErrMissing

func (s *Section) ErrMissing(p string) error

func (*Section) Error

func (s *Section) Error(v interface{}, args ...interface{}) error

func (*Section) FindParameter

func (s *Section) FindParameter(parameter string) *Parameter

Parameter returns a pointer to the parameter structure with the given name

func (Section) First

func (s Section) First(parameter string) (v *Value)

func (Section) FirstOrDefault

func (s Section) FirstOrDefault(parameter string, defval *Value) (v *Value)

func (Section) Float32

func (s Section) Float32(parameter string) (float32, bool)

func (Section) Float32OrDefault

func (s Section) Float32OrDefault(parameter string, defval float32) float32

func (Section) Float64

func (s Section) Float64(parameter string) (float64, bool)

func (Section) Float64OrDefault

func (s Section) Float64OrDefault(parameter string, defval float64) float64

func (Section) Floats32

func (s Section) Floats32(parameter string) (result []float32)

func (Section) Floats64

func (s Section) Floats64(parameter string) (result []float64)

func (Section) IP

func (s Section) IP(parameter string) net.IP

func (Section) IP4

func (s Section) IP4(parameter string) net.IP

func (Section) IP4s

func (s Section) IP4s(parameter string) (result []net.IP)

func (Section) IP6

func (s Section) IP6(parameter string) net.IP

func (Section) IP6s

func (s Section) IP6s(parameter string) (result []net.IP)

func (Section) IPs

func (s Section) IPs(parameter string) (result []net.IP)

func (Section) Int

func (s Section) Int(parameter string) (int, bool)

func (Section) Int32

func (s Section) Int32(parameter string) (int32, bool)

func (Section) Int32OrDefault

func (s Section) Int32OrDefault(parameter string, defval int32) int32

func (Section) Int64

func (s Section) Int64(parameter string) (int64, bool)

func (Section) Int64OrDefault

func (s Section) Int64OrDefault(parameter string, defval int64) int64

func (Section) IntOrDefault

func (s Section) IntOrDefault(parameter string, defval int) int

func (Section) Interpreted

func (s Section) Interpreted(parameter string) []string

func (Section) Ints

func (s Section) Ints(parameter string) (result []int)

func (Section) Ints32

func (s Section) Ints32(parameter string) (result []int32)

func (Section) Ints64

func (s Section) Ints64(parameter string) (result []int64)

func (*Section) IsInherited

func (s *Section) IsInherited(parameter string) bool

IsInherited returns true if the parameter with the given name was set and inherited from a parent or default section.

func (Section) IsOff

func (s Section) IsOff(parameter string) bool

func (Section) IsOn

func (s Section) IsOn(parameter string) bool

func (*Section) IsSet

func (s *Section) IsSet(parameter string) bool

IsSet returns true if the parameter with the given name was set

func (Section) Last

func (s Section) Last(parameter string) (v *Value)

func (Section) LastOrDefault

func (s Section) LastOrDefault(parameter string, defval *Value) (v *Value)

func (*Section) Need

func (s *Section) Need(parameters ...string) error

Need checks whether the given parameters are set and non-empty and returns an error otherwise.

func (Section) NeedString

func (s Section) NeedString(parameter string) (string, error)

func (Section) NeedValue

func (s Section) NeedValue(parameter string) (*Value, error)

func (Section) NeedValues

func (s Section) NeedValues(parameter string) (*Values, error)

func (Section) NonEmptyStringOrDefault

func (s Section) NonEmptyStringOrDefault(parameter string, defval string) string

func (*Section) Parameter

func (s *Section) Parameter(parameter string) *Parameter

RawParameter returns a pointer to the named parameter's structure, or nil if there's no parameter with this name.

func (*Section) ParameterNames

func (s *Section) ParameterNames() (result []string)

ParameterNames returns the names of all parameters in this section.

func (*Section) Parameters

func (s *Section) Parameters() *[]Parameter

Parameters returns all parameters in this section.

func (Section) Raw

func (s Section) Raw(parameter string) []string

func (Section) String

func (s Section) String(parameter string) string

func (Section) StringOrDefault

func (s Section) StringOrDefault(parameter string, defval string) string

func (Section) Strings

func (s Section) Strings(parameter string) (result []string)

func (*Section) Tag

func (s *Section) Tag() string

Tag returns a string identifying this section by name and, if non-empty, ID

func (Section) Tokens

func (s Section) Tokens(parameter string, downcase bool) (tokens []string)

func (Section) Unique

func (s Section) Unique(parameter string, ignorecase bool) (result Values)

func (Section) UniqueTokens

func (s Section) UniqueTokens(parameter string, downcase bool) (tokens []string)

func (Section) Value

func (s Section) Value(parameter string) (v *Value)

func (Section) Values

func (s Section) Values(parameter string) (result *Values)

type SectionSplitterFunc

type SectionSplitterFunc func(*ParseContext, string) (string, string, bool)

type Source

type Source interface {
	Text() string
}

type Tags

type Tags map[string][]string

func ParseTags

func ParseTags(words []string) Tags

func (Tags) AnyOf

func (t Tags) AnyOf(keys ...string) bool

func (Tags) First

func (t Tags) First(k string) string

func (Tags) Has

func (t Tags) Has(k string) bool

func (Tags) HasOneValue

func (t Tags) HasOneValue(k string) bool

func (Tags) HasValue

func (t Tags) HasValue(k string) bool

func (Tags) Last

func (t Tags) Last(k string) string

func (Tags) One

func (t Tags) One(k string) string

type UndefineSplitterFunc

type UndefineSplitterFunc func(*ParseContext, string) (string, bool)

type Value

type Value struct {
	Data      string
	Source    textfile.LineSource
	Parameter *Parameter
}

func (Value) AbsolutePath

func (v Value) AbsolutePath(p string) (result string, err error)

func (*Value) Any

func (v *Value) Any() bool

func (*Value) Empty

func (v *Value) Empty() bool

func (Value) ErrEmpty

func (v Value) ErrEmpty() error

func (Value) ErrInvalid

func (v Value) ErrInvalid() error

func (Value) Error

func (v Value) Error(i interface{}, args ...interface{}) error

func (Value) Float

func (v Value) Float() (float64, bool)

func (Value) Float32

func (v Value) Float32() (float32, bool)

func (Value) Float64

func (v Value) Float64() (float64, bool)

func (Value) IP

func (v Value) IP() net.IP

func (Value) IP4

func (v Value) IP4() net.IP

func (Value) IP6

func (v Value) IP6() net.IP

func (Value) Int

func (v Value) Int() (int, bool)

func (Value) Int32

func (v Value) Int32() (int32, bool)

func (Value) Int64

func (v Value) Int64() (int64, bool)

func (Value) Interpreted

func (v Value) Interpreted() string

func (Value) IsOff

func (v Value) IsOff() bool

func (Value) IsOn

func (v Value) IsOn() bool

func (Value) Path

func (v Value) Path() string

func (Value) PathFor

func (v Value) PathFor(relpath string) string

func (Value) Raw

func (v Value) Raw() string

func (Value) RelativePath

func (v Value) RelativePath(p string) string

func (Value) String

func (v Value) String() string

func (Value) StringOrDefault

func (v Value) StringOrDefault(def string) string

func (*Value) StringWithTags

func (v *Value) StringWithTags() (string, Tags, error)

func (*Value) Tags

func (v *Value) Tags() (Tags, error)

func (Value) Tokens

func (v Value) Tokens(downcase bool) (tokens []string)

func (Value) UniqueTokens

func (v Value) UniqueTokens(downcase bool) (tokens []string)

type Values

type Values []Value

func (Values) First

func (vals Values) First() (v *Value)

func (Values) FirstOrDefault

func (vals Values) FirstOrDefault(defval *Value) (v *Value)

func (Values) Float32

func (vals Values) Float32() (float32, bool)

func (Values) Float32OrDefault

func (vals Values) Float32OrDefault(defval float32) (result float32)

func (Values) Float64

func (vals Values) Float64() (float64, bool)

func (Values) Float64OrDefault

func (vals Values) Float64OrDefault(defval float64) (result float64)

func (Values) Floats32

func (vals Values) Floats32() (result []float32)

func (Values) Floats64

func (vals Values) Floats64() (result []float64)

func (Values) IP

func (vals Values) IP() net.IP

func (Values) IP4

func (vals Values) IP4() net.IP

func (Values) IP4OrDefault

func (vals Values) IP4OrDefault(defval net.IP) (result net.IP)

func (Values) IP4s

func (vals Values) IP4s() (result []net.IP)

func (Values) IP6

func (vals Values) IP6() net.IP

func (Values) IP6OrDefault

func (vals Values) IP6OrDefault(defval net.IP) (result net.IP)

func (Values) IP6s

func (vals Values) IP6s() (result []net.IP)

func (Values) IPOrDefault

func (vals Values) IPOrDefault(defval net.IP) (result net.IP)

func (Values) IPs

func (vals Values) IPs() (result []net.IP)

func (Values) Int

func (vals Values) Int() (int, bool)

func (Values) Int32

func (vals Values) Int32() (int32, bool)

func (Values) Int32OrDefault

func (vals Values) Int32OrDefault(defval int32) (result int32)

func (Values) Int64

func (vals Values) Int64() (int64, bool)

func (Values) Int64OrDefault

func (vals Values) Int64OrDefault(defval int64) (result int64)

func (Values) IntOrDefault

func (vals Values) IntOrDefault(defval int) (result int)

func (Values) Interpreted

func (vals Values) Interpreted() (result []string)

func (Values) Ints

func (vals Values) Ints() (result []int)

func (Values) Ints32

func (vals Values) Ints32() (result []int32)

func (Values) Ints64

func (vals Values) Ints64() (result []int64)

func (Values) IsOff

func (vals Values) IsOff() bool

func (Values) IsOn

func (vals Values) IsOn() bool

func (Values) Last

func (vals Values) Last() (v *Value)

func (Values) LastOrDefault

func (vals Values) LastOrDefault(defval *Value) (v *Value)

func (Values) NonEmptyStringOrDefault

func (vals Values) NonEmptyStringOrDefault(defval string) (result string)

func (Values) Raw

func (vals Values) Raw() (result []string)

func (Values) String

func (vals Values) String() string

func (Values) StringOrDefault

func (vals Values) StringOrDefault(defval string) string

func (Values) Strings

func (vals Values) Strings() (result []string)

func (Values) Tokens

func (vals Values) Tokens(downcase bool) (tokens []string)

func (Values) Unique

func (vals Values) Unique(ignorecase bool) (result Values)

func (Values) UniqueTokens

func (vals Values) UniqueTokens(downcase bool) (tokens []string)

Jump to

Keyboard shortcuts

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