Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when trying to get empty value from Setting. ErrNotFound = errors.New("key was not found") // ErrParsingBool is returned when Setting.Bool() method is called and Setting.Value // can not be interpreted as boolean. ErrParsingBool = errors.New("value can not be interpreted as bool") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Settings store key value pairs ("key = value" in config file)
Settings map[string]string
// Options store single valued options ("option" in config file)
Options map[string]struct{}
}
Config holds keys and values parsed from file, io.Reader, or io.ReadCloser You can access Config.Settings and Config.Options directly.
func ParseFile ¶
ParseFile reads Config from file. It returns nil and error if os.Open(filename) fails. It would be wise to always check returned error. ParseFile captures two types of values: "key = value" and "option". Either key value pair or option must be put in its own line in the file. key or option must be a single word. In example line "option1 option2" only option1 will be captured. Thus option2 needs to be put in a separate line in the file. In line "key = value1 value2 value3" all of value1, value2, and value3 will be captured.
func ParseReadCloser ¶ added in v0.2.1
func ParseReadCloser(r io.ReadCloser) *Config
ParseReadCloser reads Config from r and calls r.Close(). See also ParseFile.
func ParseReader ¶
ParseReader reads Config from r. See also ParseFile.
func (*Config) GetSetting ¶ added in v0.2.1
Get returns Setting. If key was not found Setting's Value will be empty string
func (*Config) HasOption ¶ added in v0.2.1
HasOption returns true if line:
"key"
was present in the parsed file
func (*Config) HasSetting ¶ added in v0.2.1
HasSetting returns true if line:
"key = somevalue"
was present in the parsed file
type Setting ¶ added in v0.2.1
type Setting struct {
// Key holds the name of key parsed from the configuration
Key string
// Value holds the value of key parsed from the configuration
Value string
// Found is set to true if Key was found in the parsed config, false otherwise
Found bool
}
Option represents single valuse read from config
func (Setting) Bool ¶ added in v0.2.1
Bool tries to interpret option Value as bool "1", "true", "yes" (case insensitive) yields true "0", "false", "no" (case insensitive) yields false
func (Setting) Float64 ¶ added in v0.2.1
Float64 converts Option's Value to float64 if possible If setting was not found in the config this method will return ErrNotFound
func (Setting) Int ¶ added in v0.2.1
Int converts Option's Value to int if possible If option was not found in the config this method will return ErrNotFound
func (Setting) Split ¶ added in v0.2.1
Split splits Setting's value with separator sep and returns []Setting. If separator was not found the method returns slice with only one Setting. This method is intended for use when config file has comma (or any other delimiter) separated values like:
myoption = first,second,third
Split(",") will return slice with 3 separate Setting each holding one of "first, second, third"