Documentation ¶
Index ¶
- Constants
- func NewLexer(filename, contents string) *lexer
- type Configuration
- func (c *Configuration) Decode(section string, structPtr interface{}) (err error)
- func (c *Configuration) Get(option string) (interface{}, error)
- func (c *Configuration) GetBool(option string) (bool, error)
- func (c *Configuration) GetBoolArray(option string) ([]bool, error)
- func (c *Configuration) GetBoolArrayDefault(option string, dfault []bool) []bool
- func (c *Configuration) GetBoolDefault(option string, dfault bool) bool
- func (c *Configuration) GetDate(option string) (time.Time, error)
- func (c *Configuration) GetDateArray(option string) ([]time.Time, error)
- func (c *Configuration) GetDateArrayDefault(option string, dfault []time.Time) []time.Time
- func (c *Configuration) GetDateDefault(option string, dfault time.Time) time.Time
- func (c *Configuration) GetFloat(option string) (float64, error)
- func (c *Configuration) GetFloatArray(option string) ([]float64, error)
- func (c *Configuration) GetFloatArrayDefault(option string, dfault []float64) []float64
- func (c *Configuration) GetFloatDefault(option string, dfault float64) float64
- func (c *Configuration) GetInt(option string) (int64, error)
- func (c *Configuration) GetIntArray(option string) ([]int64, error)
- func (c *Configuration) GetIntArrayDefault(option string, dfault []int64) []int64
- func (c *Configuration) GetIntDefault(option string, dfault int64) int64
- func (c *Configuration) GetString(option string) (string, error)
- func (c *Configuration) GetStringArray(option string) ([]string, error)
- func (c *Configuration) GetStringArrayDefault(option string, dfault []string) []string
- func (c *Configuration) GetStringDefault(option string, dfault string) string
- func (c *Configuration) HasOption(option string) (result bool)
- func (c *Configuration) IsSection(section string) bool
- func (c *Configuration) Len() (length int)
- func (c *Configuration) LoadFile(filename string) (err *ConfigurationError)
- func (c *Configuration) LoadString(contents string) (err *ConfigurationError)
- func (c *Configuration) Options(section string) (options []string)
- func (c *Configuration) Sections() (sections []string)
- func (c *Configuration) String() string
- type ConfigurationError
- type Parser
Constants ¶
const ( TkEOF kind = iota // End-of-file token. TkEOL // End-of-line token. TkError // An error occurred; value is error message. TkIdentifier // Identifier token. TkBool // Boolean. TkString // A string (does not include double quotes). TkInt // An integer. TkFloat // A floating point number. TkDate // A date. TkEqual // '='. TkLBracket // '['. TkRBracket // ']'. TkComma // ','. )
Tokens returned by lexer.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Configuration ¶
Configuration context.
func NewConfiguration ¶
func NewConfiguration() (c *Configuration)
NewConfiguration creates a new configuration context.
func (*Configuration) Decode ¶
func (c *Configuration) Decode(section string, structPtr interface{}) (err error)
Decode initializes structPtr with contents of given section. Function does not support circular types; it will loop forever.
func (*Configuration) Get ¶
func (c *Configuration) Get(option string) (interface{}, error)
Get returns the value (scalar or array) associated with given option name, or nil if option is undefined. option is a dot-separated path (e.g. section.option).
func (*Configuration) GetBool ¶
func (c *Configuration) GetBool(option string) (bool, error)
GetBool returns the boolean value associated with given option name. An error is flagged if option does not record a boolean value or it is undefined.
func (*Configuration) GetBoolArray ¶
func (c *Configuration) GetBoolArray(option string) ([]bool, error)
GetBoolArray returns the array of booleans associated with given option name. An error is flagged if option does not record an array of booleans or it is undefined.
func (*Configuration) GetBoolArrayDefault ¶
func (c *Configuration) GetBoolArrayDefault(option string, dfault []bool) []bool
GetBoolArrayDefault is similar to GetBoolArray but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetBoolDefault ¶
func (c *Configuration) GetBoolDefault(option string, dfault bool) bool
GetBoolDefault is similar to GetBool but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetDate ¶
func (c *Configuration) GetDate(option string) (time.Time, error)
GetDate returns the date associated with given option name. An error is flagged if option does not record a date or it is undefined.
func (*Configuration) GetDateArray ¶
func (c *Configuration) GetDateArray(option string) ([]time.Time, error)
GetDateArray returns the array of dates associated with given option name. An error is flagged if option does not record an array of dates or it is undefined.
func (*Configuration) GetDateArrayDefault ¶
GetDateArrayDefault is similar to GetDateArray but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetDateDefault ¶
GetDateDefault is similar to GetDate but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetFloat ¶
func (c *Configuration) GetFloat(option string) (float64, error)
GetFloat returns the floating-point number associated with given option name. An error is flagged if option does not record a floating-point number or it is undefined.
func (*Configuration) GetFloatArray ¶
func (c *Configuration) GetFloatArray(option string) ([]float64, error)
GetFloatArray returns the array of floating-point values associated with given option name. An error is flagged if option does not record an array of floating-point values or it is undefined.
func (*Configuration) GetFloatArrayDefault ¶
func (c *Configuration) GetFloatArrayDefault(option string, dfault []float64) []float64
GetFloatArrayDefault is similar to GetFloatArray but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetFloatDefault ¶
func (c *Configuration) GetFloatDefault(option string, dfault float64) float64
GetFloatDefault is similar to GetFloat but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetInt ¶
func (c *Configuration) GetInt(option string) (int64, error)
GetInt returns the integer associated with given option name. An error is flagged if option does not record an integer or it is undefined.
func (*Configuration) GetIntArray ¶
func (c *Configuration) GetIntArray(option string) ([]int64, error)
GetIntArray returns the array of integers associated with given option name. An error is flagged if option does not record an array of integers or it is undefined.
func (*Configuration) GetIntArrayDefault ¶
func (c *Configuration) GetIntArrayDefault(option string, dfault []int64) []int64
GetIntArrayDefault is similar to GetIntArray but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetIntDefault ¶
func (c *Configuration) GetIntDefault(option string, dfault int64) int64
GetIntDefault is similar to GetInt but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetString ¶
func (c *Configuration) GetString(option string) (string, error)
GetString returns the string associated with given option name. An error is flagged if option does not record a string or it is undefined.
func (*Configuration) GetStringArray ¶
func (c *Configuration) GetStringArray(option string) ([]string, error)
GetStringArray returns the array of strings associated with given option name. An error is flagged if option does not record an array of strings or it is undefined.
func (*Configuration) GetStringArrayDefault ¶
func (c *Configuration) GetStringArrayDefault(option string, dfault []string) []string
GetStringArrayDefault is similar to GetStringArray but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) GetStringDefault ¶
func (c *Configuration) GetStringDefault(option string, dfault string) string
GetStringDefault is similar to GetString but given default value is returned if option does not exist or is of wrong type.
func (*Configuration) HasOption ¶
func (c *Configuration) HasOption(option string) (result bool)
HasOption returns true if given option is defined, false otherwise.
func (*Configuration) IsSection ¶
func (c *Configuration) IsSection(section string) bool
IsSection returns true if given section exists, otherwise false.
func (*Configuration) Len ¶
func (c *Configuration) Len() (length int)
Len returns the number of options defined.
func (*Configuration) LoadFile ¶
func (c *Configuration) LoadFile(filename string) (err *ConfigurationError)
LoadFile loads the configuration stored in given file.
func (*Configuration) LoadString ¶
func (c *Configuration) LoadString(contents string) (err *ConfigurationError)
LoadString loads the configuration stored in given string.
func (*Configuration) Options ¶
func (c *Configuration) Options(section string) (options []string)
Options returns the options defined in given section sorted in ascending order. Optionsglobally defined are returned if given section is an empty string.
func (*Configuration) Sections ¶
func (c *Configuration) Sections() (sections []string)
Sections returns the sections defined sorted in ascending order.
func (*Configuration) String ¶
func (c *Configuration) String() string
String dumps a configuration to a string.
type ConfigurationError ¶
type ConfigurationError struct { Filename string // Filename. Line, Column int // Line and column. // contains filtered or unexported fields }
ConfigurationError records parsing errors.
func (*ConfigurationError) Error ¶
func (c *ConfigurationError) Error() string
Error dumps a configuration-error to a string.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser context.
func NewStringParser ¶
NewStringParser instanciates a parser for given configuration string.
func (*Parser) Parse ¶
func (p *Parser) Parse(c *Configuration) (err *ConfigurationError)
Parse parses a configuration stored either in a file or a string.