ini

package module
v0.0.0-...-6c03fb7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2019 License: BSD-2-Clause Imports: 16 Imported by: 1

README

ini

Build Status

Build Status

Overview

ini is a Go package which provides a basic object model of ini configuration files.

License

This Go package is release under a BSD-style license, the contents of which are in the repo's LICENSE file.

API Documentation

http://godoc.org/github.com/xaevman/ini

Documentation

Overview

Package ini provides basic facilities for parsing and monitoring changes to ini format configuration files.

Index

Constants

View Source
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

View Source
var VoidSection = newIniSection("void")

VoidSection is returned by GetSection so that subsequent calls to GetVal can be made without nil checking.

View Source
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 ForceUpdate

func ForceUpdate()

ForceUpdate cause an ini poll to happen via manual request.

func SetPollFreqSec

func SetPollFreqSec(freqSec uint32)

SetPollFreqSec sets the frequency at which the underlying ini file is checked for changes.

func Shutdown

func Shutdown()

func Subscribe

func Subscribe(cfg *IniCfg, callback func(*IniCfg, int)) uint32

Subscribe notifies the ini system that the given callback should be called upon any changes to the given ini file.

func Unsubscribe

func Unsubscribe(cfg *IniCfg, id uint32)

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 New

func New(iniPath string) *IniCfg

New returns a pointer to a new IniCfg object for the given file path.

func NewFromFiles

func NewFromFiles(iniFiles []string) *IniCfg

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

func (this *IniCfg) RawString() string

RawString prints the ini files exactly as read in from disk, along with last write time and file hash.

func (*IniCfg) Reparse

func (this *IniCfg) Reparse()

Reparse forces a config file to be re-read and all IniSections and IniValues to be reparsed. After parsing is complete, all hashes are also recomputed.

func (*IniCfg) String

func (this *IniCfg) String() string

String prints a human-readable text representation of the IniCfg object heirarchy.

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

type IniValue struct {
	Name   string
	Values []string
}

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

func (this *IniValue) GetValBool(offset int, defVal bool) bool

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

func (this *IniValue) GetValFloat(offset int, defVal float32) float32

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

func (this *IniValue) GetValFloat64(offset int, defVal float64) float64

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

func (this *IniValue) GetValInt(offset int, defVal int) int

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

func (this *IniValue) GetValInt64(offset int, defVal int64) int64

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

func (this *IniValue) GetValStr(offset int, defVal string) string

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

func (this *IniValue) GetValUint(offset int, defVal uint) uint

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

func (this *IniValue) GetValUint64(offset int, defVal uint64) uint64

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.

func (*IniValue) String

func (this *IniValue) String() string

String prints a more human-readable representation of the IniValue object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL