Documentation
¶
Overview ¶
Package ini provides basic facilities for parsing and monitoring changes to ini format configuration files.
Index ¶
- Constants
- Variables
- func ClearSubscribers(cfg *IniCfg)
- func ForceUpdate()
- func SetPollFreqSec(freqSec uint32)
- func Shutdown()
- func Subscribe(cfg *IniCfg, callback func(*IniCfg, int)) uint32
- func Unsubscribe(cfg *IniCfg, id uint32)
- type IniCfg
- type IniSection
- type IniValue
- func (this *IniValue) GetValBool(offset int, defVal bool) bool
- func (this *IniValue) GetValFloat(offset int, defVal float32) float32
- func (this *IniValue) GetValFloat64(offset int, defVal float64) float64
- func (this *IniValue) GetValInt(offset int, defVal int) int
- func (this *IniValue) GetValInt64(offset int, defVal int64) int64
- func (this *IniValue) GetValStr(offset int, defVal string) string
- func (this *IniValue) GetValUint(offset int, defVal uint) uint
- func (this *IniValue) GetValUint64(offset int, defVal uint64) uint64
- func (this *IniValue) String() string
Constants ¶
const DefaultPollFreqSec = 10
DefaultPollFreqSec is the default amount of time, in seconds, that the ini system will wait between checks to see if a given ini file has changed.
Variables ¶
var VoidSection = newIniSection("void")
VoidSection is returned by GetSection so that subsequent calls to GetVal can be made without nil checking.
var VoidValue = newIniValue("void", "")
VoidValue is returned by GetFirstValue so that subsequent calls to GetValx can be made without nil checking.
Functions ¶
func ClearSubscribers ¶
func ClearSubscribers(cfg *IniCfg)
ClearSubscribers clears the list of subscriber functions for the given ini file.
func SetPollFreqSec ¶
func SetPollFreqSec(freqSec uint32)
SetPollFreqSec sets the frequency at which the underlying ini file is checked for changes.
func Subscribe ¶
Subscribe notifies the ini system that the given callback should be called upon any changes to the given ini file.
func Unsubscribe ¶
Unsubscribe removes the callback identified by id from the list of subscribers for the given ini file.
Types ¶
type IniCfg ¶
type IniCfg struct {
ConfigVer string
Name string
// Paths is the set of all ini file paths contributing to the configuration.
// ModTimes are the corresponding modification times of each of those files.
// Raws are the similarly corresponding raw content of those files.
Paths []string
ModTimes []time.Time
Raws []string
Sections map[string]*IniSection
// contains filtered or unexported fields
}
IniCfg represents a single virtual ini configuration file, containing pointers to the IniSections contained within it. ConfigVer is a consistent hash of all IniSections within the file which is not influenced by whitespace or comments.
func NewFromFiles ¶
NewFromFiles returns a pointer to a new IniCfg object for the files at the given paths.
func (*IniCfg) GetSection ¶
func (this *IniCfg) GetSection(sectionName string) *IniSection
GetSection returns a pointer to the requested IniSection object, or nil if an IniSection object with that name is not present within the configuration
func (*IniCfg) RawString ¶
RawString prints the ini files exactly as read in from disk, along with last write time and file hash.
type IniSection ¶
type IniSection struct {
ConfigVer string
Name string
Values map[string][]*IniValue
// contains filtered or unexported fields
}
IniSection represents a section within an ini file. Section names are enclosed with square brackets (ex: [my.section.name]). Section names are case insensitive and cleaned up by forced removal of framing white space. White space within the section name is converted to an underline. There may be multiple instances of a given section name present within the ini file, but only one IniSection object will be created. In the case where multiple instances of an ini section exist within the file, the child key/value objects will be coalesced within the single IniSection object. ConfigVer is a consistent hash of all the Key/Value entries within the section which is not influenced by whitespace or comments.
func (*IniSection) AddValue ¶
func (this *IniSection) AddValue(key, value string)
AddValue adds a new IniValue object for the given key and value strings to the IniSection instance.
func (*IniSection) ComputeHash ¶
func (this *IniSection) ComputeHash()
ComputeHash recomputes the sha1 hash of all the key/val pairs within the IniSection.
func (*IniSection) GetFirstVal ¶
func (this *IniSection) GetFirstVal(valName string) *IniValue
GetFirstVal returns a pointer to the first IniValue object with a matching key name. Returns nil if no relevant IniValue objects are present in the section.
func (*IniSection) GetVals ¶
func (this *IniSection) GetVals(valName string) []*IniValue
GetVals returns an array of pointers to IniValue objects with matching key names. Returns nil if no relevant IniValue objects are present in the section.
func (*IniSection) String ¶
func (this *IniSection) String() string
String prints a human-readable representation of the IniSection and its children IniValue objects.
type IniValue ¶
IniValue represents a single Key/Value within a config section. Multiple instances of of a given key may be present within a section, and separate IniValue objects will exist for each instance of the key. Keys and values are separated by an equal sign. The value side of the key/value pair is split on a comma delimeter and trimmed of any enclosing whitepsace.
func (*IniValue) GetValBool ¶
GetValBool retrieves the value at the given offset and attempts to parse and return it as a boolean value. If either the offset is invalid, or parsing fails, the supplied default value is returned.
func (*IniValue) GetValFloat ¶
GetValFloat retrieves the value at the given offset and attempts to parse and return it as a 32bit float. If either the offset is invalid, or parsing fails, the supplied default value is returned.
func (*IniValue) GetValFloat64 ¶
GetValFloat64 retrieves the value at the given offset and attempts to parse and return it as a 64bit float. If either the offset is invalid, or parsing fails, the supplied default value is returned.
func (*IniValue) GetValInt ¶
GetValInt retrieves the value at the given offset and attempts to parse and return it as a 32bit signed integer. If either the offset is invalid, or parsing fails, the supplied default value is returned.
func (*IniValue) GetValInt64 ¶
GetValInt64 retrieves the value at the given offset and attempts to parse and return it as a 64bit signed integer. If either the offset is invalid, or parsing fails, the supplied default value is returned.
func (*IniValue) GetValStr ¶
GetValStr retrieves the value at the given offset and returns it as a string value. If teh offset is invalid the supplied default value is returned.
func (*IniValue) GetValUint ¶
GetValUint retrieves the value at the given offset and attempts to parse and return it as a 32bit unsigned integer. If either the offset is invalid, or the parsing fails, the supplied default value is returned.
func (*IniValue) GetValUint64 ¶
GetValUint64 retrieves the value at the given offset and attempts to parse and return it as a 64bit unsigned integer. If either the offset is invalid, or the parsing fails, the supplied default value is returned.