Documentation ¶
Overview ¶
goconfig is a easy-use comments-support configuration file parser.
Index ¶
- Constants
- Variables
- func SaveConfigFile(c *ConfigFile, filename string) (err error)
- type ConfigFile
- func (c *ConfigFile) Bool(section, key string) (bool, error)
- func (c *ConfigFile) Float64(section, key string) (float64, error)
- func (c *ConfigFile) GetKeyComments(section, key string) (comments string)
- func (c *ConfigFile) GetSection(section string) (map[string]string, error)
- func (c *ConfigFile) GetSectionComments(section string) (comments 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) bool
- func (c *ConfigFile) MustFloat64(section, key string) float64
- func (c *ConfigFile) MustInt(section, key string) int
- func (c *ConfigFile) MustInt64(section, key string) int64
- func (c *ConfigFile) MustValue(section, key string) string
- 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 ReadError
Constants ¶
const ( // Default section name. DEFAULT_SECTION = "DEFAULT" // Get Errors. SectionNotFound = iota KeyNotFound // Read Errors. BlankSection // Get and Read Errors. CouldNotParse )
Variables ¶
var (
// Line break
LineBreak = "\r\n"
)
Functions ¶
func SaveConfigFile ¶
func SaveConfigFile(c *ConfigFile, filename string) (err error)
SaveConfigFile writes configuration file to local file system
Types ¶
type ConfigFile ¶
type ConfigFile struct {
// contains filtered or unexported fields
}
ConfigFile is the representation of configuration settings. The public interface is entirely through methods.
func LoadConfigFile ¶
func LoadConfigFile(filename string) (c *ConfigFile, err error)
LoadConfigFile reads a file and returns a new configuration representation. This representation can be queried with GetValue.
func (*ConfigFile) Bool ¶
func (c *ConfigFile) Bool(section, key string) (bool, error)
Bool returns bool type value.
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) 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) 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 if the section or (default)key does not exist and empty string value.
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) bool
MustBool always returns value without error, it returns false if error occurs.
func (*ConfigFile) MustFloat64 ¶
func (c *ConfigFile) MustFloat64(section, key string) float64
MustFloat64 always returns value without error, it returns 0.0 if error occurs.
func (*ConfigFile) MustInt ¶
func (c *ConfigFile) MustInt(section, key string) int
MustInt always returns value without error, it returns 0 if error occurs.
func (*ConfigFile) MustInt64 ¶
func (c *ConfigFile) MustInt64(section, key string) int64
MustInt64 always returns value without error, it returns 0 if error occurs.
func (*ConfigFile) MustValue ¶
func (c *ConfigFile) MustValue(section, key string) string
MustValue always returns value without error, it returns empty string if error occurs.
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, and 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, and 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. If value is an empty string(0 length), it will remove its section-key and its comments! It returns true if the key and value were inserted or removed, and false if the value was overwritten. If the section does not exist in advance, it is created.