Documentation ¶
Index ¶
- Constants
- Variables
- func SaveConfigData(c *ConfigFile, out io.Writer) (err error)
- func SaveConfigFile(c *ConfigFile, filename string) (err error)
- type ConfigFile
- func (c *ConfigFile) AppendFiles(files ...string) error
- func (c *ConfigFile) Bool(section, key string) (bool, error)
- func (c *ConfigFile) DeleteKey(section, key string) bool
- func (c *ConfigFile) DeleteSection(section string) bool
- func (c *ConfigFile) Float64(section, key string) (float64, error)
- func (c *ConfigFile) GetKeyComments(section, key string) (comments string)
- func (c *ConfigFile) GetKeyList(section string) []string
- func (c *ConfigFile) GetSection(section string) (map[string]string, error)
- func (c *ConfigFile) GetSectionComments(section string) (comments string)
- func (c *ConfigFile) GetSectionList() []string
- func (c *ConfigFile) GetValue(section, key string) (string, error)
- func (c *ConfigFile) Int(section, key string) (int, error)
- func (c *ConfigFile) Int64(section, key string) (int64, error)
- func (c *ConfigFile) MustBool(section, key string, defaultVal ...bool) bool
- func (c *ConfigFile) MustFloat64(section, key string, defaultVal ...float64) float64
- func (c *ConfigFile) MustInt(section, key string, defaultVal ...int) int
- func (c *ConfigFile) MustInt64(section, key string, defaultVal ...int64) int64
- func (c *ConfigFile) MustValue(section, key string, defaultVal ...string) string
- func (c *ConfigFile) MustValueArray(section, key, delim string) []string
- func (c *ConfigFile) MustValueRange(section, key, defaultVal string, candidates []string) string
- func (c *ConfigFile) MustValueSet(section, key string, defaultVal ...string) (string, bool)
- func (c *ConfigFile) Reload() (err error)
- func (c *ConfigFile) ReloadData(in io.Reader) (err error)
- func (c *ConfigFile) SetKeyComments(section, key, comments string) bool
- func (c *ConfigFile) SetSectionComments(section, comments string) bool
- func (c *ConfigFile) SetValue(section, key, value string) bool
- type ParseError
Constants ¶
const (
// Default section name.
DEFAULT_SECTION = "DEFAULT"
)
Variables ¶
var LineBreak = "\n"
var PrettyFormat = true
Write spaces around "=" to look better.
Functions ¶
func SaveConfigData ¶
func SaveConfigData(c *ConfigFile, out io.Writer) (err error)
SaveConfigData writes configuration to a writer
func SaveConfigFile ¶
func SaveConfigFile(c *ConfigFile, filename string) (err error)
SaveConfigFile writes configuration file to local file system
Types ¶
type ConfigFile ¶
type ConfigFile struct { BlockMode bool // Indicates whether use lock or not. // contains filtered or unexported fields }
A ConfigFile represents a INI formar configuration file.
func LoadConfigFile ¶
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error)
LoadConfigFile reads a file and returns a new configuration representation. This representation can be queried with GetValue.
func LoadFromData ¶
func LoadFromData(data []byte) (c *ConfigFile, err error)
LoadFromData accepts raw data directly from memory and returns a new configuration representation. Note that the configuration is written to the system temporary folder, so your file should not contain sensitive information.
func LoadFromReader ¶
func LoadFromReader(in io.Reader) (c *ConfigFile, err error)
LoadFromReader accepts raw data directly from a reader and returns a new configuration representation. You must use ReloadData to reload. You cannot append files a configfile read this way.
func (*ConfigFile) AppendFiles ¶
func (c *ConfigFile) AppendFiles(files ...string) error
AppendFiles appends more files to ConfigFile and reload automatically.
func (*ConfigFile) Bool ¶
func (c *ConfigFile) Bool(section, key string) (bool, error)
Bool returns bool type value.
func (*ConfigFile) DeleteKey ¶
func (c *ConfigFile) DeleteKey(section, key string) bool
DeleteKey deletes the key in given section. It returns true if the key was deleted, or returns false if the section or key didn't exist.
func (*ConfigFile) DeleteSection ¶
func (c *ConfigFile) DeleteSection(section string) bool
DeleteSection deletes the entire section by given name. It returns true if the section was deleted, and false if the section didn't exist.
func (*ConfigFile) Float64 ¶
func (c *ConfigFile) Float64(section, key string) (float64, error)
Float64 returns float64 type value.
func (*ConfigFile) GetKeyComments ¶
func (c *ConfigFile) GetKeyComments(section, key string) (comments string)
GetKeyComments returns the comments of key in the given section. It returns an empty string(0 length) if the comments do not exist.
func (*ConfigFile) GetKeyList ¶
func (c *ConfigFile) GetKeyList(section string) []string
GetKeyList returns the list of all keys in give section in the same order in the file. It returns nil if given section does not exist.
func (*ConfigFile) GetSection ¶
func (c *ConfigFile) GetSection(section string) (map[string]string, error)
GetSection returns key-value pairs in given section. It section does not exist, returns nil and error.
func (*ConfigFile) GetSectionComments ¶
func (c *ConfigFile) GetSectionComments(section string) (comments string)
GetSectionComments returns the comments in the given section. It returns an empty string(0 length) if the comments do not exist.
func (*ConfigFile) GetSectionList ¶
func (c *ConfigFile) GetSectionList() []string
GetSectionList returns the list of all sections in the same order in the file.
func (*ConfigFile) GetValue ¶
func (c *ConfigFile) GetValue(section, key string) (string, error)
GetValue returns the value of key available in the given section. If the value needs to be unfolded (see e.g. %(google)s example in the GoConfig_test.go), then String does this unfolding automatically, up to _DEPTH_VALUES number of iterations. It returns an error and empty string value if the section does not exist, or key does not exist in DEFAULT and current sections.
func (*ConfigFile) Int ¶
func (c *ConfigFile) Int(section, key string) (int, error)
Int returns int type value.
func (*ConfigFile) Int64 ¶
func (c *ConfigFile) Int64(section, key string) (int64, error)
Int64 returns int64 type value.
func (*ConfigFile) MustBool ¶
func (c *ConfigFile) MustBool(section, key string, defaultVal ...bool) bool
MustBool always returns value without error, it returns false if error occurs.
func (*ConfigFile) MustFloat64 ¶
func (c *ConfigFile) MustFloat64(section, key string, defaultVal ...float64) float64
MustFloat64 always returns value without error, it returns 0.0 if error occurs.
func (*ConfigFile) MustInt ¶
func (c *ConfigFile) MustInt(section, key string, defaultVal ...int) int
MustInt always returns value without error, it returns 0 if error occurs.
func (*ConfigFile) MustInt64 ¶
func (c *ConfigFile) MustInt64(section, key string, defaultVal ...int64) int64
MustInt64 always returns value without error, it returns 0 if error occurs.
func (*ConfigFile) MustValue ¶
func (c *ConfigFile) MustValue(section, key string, defaultVal ...string) string
MustValue always returns value without error. It returns empty string if error occurs, or the default value if given.
func (*ConfigFile) MustValueArray ¶
func (c *ConfigFile) MustValueArray(section, key, delim string) []string
MustValueArray always returns value array without error, it returns empty array if error occurs, split by delimiter otherwise.
func (*ConfigFile) MustValueRange ¶
func (c *ConfigFile) MustValueRange(section, key, defaultVal string, candidates []string) string
MustValueRange always returns value without error, it returns default value if error occurs or doesn't fit into range.
func (*ConfigFile) MustValueSet ¶
func (c *ConfigFile) MustValueSet(section, key string, defaultVal ...string) (string, bool)
MustValue always returns value without error, It returns empty string if error occurs, or the default value if given, and a bool value indicates whether default value is returned.
func (*ConfigFile) Reload ¶
func (c *ConfigFile) Reload() (err error)
Reload reloads configuration file in case it has changes.
func (*ConfigFile) ReloadData ¶
func (c *ConfigFile) ReloadData(in io.Reader) (err error)
ReloadData reloads configuration file from memory
func (*ConfigFile) SetKeyComments ¶
func (c *ConfigFile) SetKeyComments(section, key, comments string) bool
SetKeyComments adds new section-key comments to the configuration. If comments are empty(0 length), it will remove its section-key comments! It returns true if the comments were inserted or removed, or returns false if the comments were overwritten. If the section does not exist in advance, it is created.
func (*ConfigFile) SetSectionComments ¶
func (c *ConfigFile) SetSectionComments(section, comments string) bool
SetSectionComments adds new section comments to the configuration. If comments are empty(0 length), it will remove its section comments! It returns true if the comments were inserted or removed, or returns false if the comments were overwritten.
func (*ConfigFile) SetValue ¶
func (c *ConfigFile) SetValue(section, key, value string) bool
SetValue adds a new section-key-value to the configuration. It returns true if the key and value were inserted, or returns false if the value was overwritten. If the section does not exist in advance, it will be created.
type ParseError ¶
type ParseError int
const ( ERR_SECTION_NOT_FOUND ParseError = iota + 1 ERR_KEY_NOT_FOUND ERR_BLANK_SECTION_NAME ERR_COULD_NOT_PARSE )