Documentation ¶
Overview ¶
Package mini implements a simple ini file parser.
The ini syntax supported includes:
* The standard name=value * Comments on new lines starting with # or ; * Blank lines * Sections labelled with [sectionname] * Split sections, using the same section in more than one place * Encoded strings, strings containing \n, \t, etc... * Array values using repeated keys named in the form key[]=value * Global key/value pairs that appear before the first section
Repeated keys, that aren't array keys, replace their previous value.
copyright © 2015 Fog Creek Software, Inc.
Index ¶
- type Config
- func (config *Config) Boolean(key string, def bool) bool
- func (config *Config) BooleanFromSection(sectionName string, key string, def bool) bool
- func (config *Config) DataFromSection(sectionName string, data interface{}) bool
- func (config *Config) Float(key string, def float64) float64
- func (config *Config) FloatFromSection(sectionName string, key string, def float64) float64
- func (config *Config) Floats(key string) []float64
- func (config *Config) FloatsFromSection(sectionName string, key string) []float64
- func (config *Config) InitializeFromPath(path string) error
- func (config *Config) InitializeFromReader(input io.Reader) error
- func (config *Config) Integer(key string, def int64) int64
- func (config *Config) IntegerFromSection(sectionName string, key string, def int64) int64
- func (config *Config) Integers(key string) []int64
- func (config *Config) IntegersFromSection(sectionName string, key string) []int64
- func (config *Config) Keys() []string
- func (config *Config) KeysForSection(sectionName string) []string
- func (config *Config) SectionNames() []string
- func (config *Config) SetName(name string)
- func (config *Config) String(key string, def string) string
- func (config *Config) StringFromSection(sectionName string, key string, def string) string
- func (config *Config) Strings(key string) []string
- func (config *Config) StringsFromSection(sectionName string, key string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the contents of an ini file organized into sections.
func LoadConfiguration ¶
LoadConfiguration takes a path, treats it as a file and scans it for an ini configuration.
func LoadConfigurationFromReader ¶
LoadConfigurationFromReader takes a reader and scans it for an ini configuration. The caller should close the reader.
func (*Config) Boolean ¶
Boolean looks for the specified key and returns it as a bool. If not found the default value def is returned.
func (*Config) BooleanFromSection ¶
BooleanFromSection looks for the specified key and returns it as a boolean. If not found the default value def is returned.
If the section name matches the config.name or "" the global data is searched.
func (*Config) DataFromSection ¶
DataFromSection reads the values of a section into a struct. The values should be of the types:
bool string []string int64 []int64 float64 []float64
Values that are missing in the section are not set, and values that are missing in the struct but present in the section are ignored.
If the section name matches the config.name or "" the global data is searched.
func (*Config) Float ¶
Float looks for the specified key and returns it as a float. If not found the default value def is returned.
func (*Config) FloatFromSection ¶
FloatFromSection looks for the specified key and returns it as a float. If not found the default value def is returned.
If the section name matches the config.name or "" the global data is searched.
func (*Config) Floats ¶
Floats looks for an array of floats under the provided key. If no matches are found nil is returned.
func (*Config) FloatsFromSection ¶
FloatsFromSection looks for an array of floats in the provided section and under the provided key. If no matches are found nil is returned.
If the section name matches the config.name or "" the global data is searched.
func (*Config) InitializeFromPath ¶
InitializeFromPath takes a path, treats it as a file and scans it for an ini configuration.
func (*Config) InitializeFromReader ¶
InitializeFromReader takes a reader and scans it for an ini configuration. The caller should close the reader.
func (*Config) Integer ¶
Integer looks for the specified key and returns it as an int. If not found the default value def is returned.
func (*Config) IntegerFromSection ¶
IntegerFromSection looks for the specified key and returns it as an int64. If not found the default value def is returned.
If the section name matches the config.name or "" the global data is searched.
func (*Config) Integers ¶
Integers looks for an array of ints under the provided key. If no matches are found nil is returned.
func (*Config) IntegersFromSection ¶
IntegersFromSection looks for an array of integers in the provided section and under the provided key. If no matches are found nil is returned.
func (*Config) KeysForSection ¶
KeysForSection returns all of the keys found in the section named sectionName.
If the section name matches the config.name or "" the global data is searched.
func (*Config) SectionNames ¶
SectionNames returns the names for each of the sections in a config structure. If the config was assigned a name, that name is included in the list. If the name is not set, then only explicitely named sections are returned.
func (*Config) SetName ¶
SetName sets the config's name, which allows it to be returned in SectionNames, or in get functions that take a name.
func (*Config) String ¶
String looks for the specified key and returns it as a string. If not found the default value def is returned.
func (*Config) StringFromSection ¶
StringFromSection looks for the specified key and returns it as a string. If not found the default value def is returned.
If the section name matches the config.name or "" the global data is searched.
func (*Config) Strings ¶
Strings looks for an array of strings under the provided key. If no matches are found nil is returned. If only one matches an array of 1 is returned.
func (*Config) StringsFromSection ¶
StringsFromSection returns the value of an array key, if the value of the key is a non-array, then that value is returned in an array of length 1.
If the section name matches the config.name or "" the global data is searched.