Documentation
¶
Overview ¶
Package ini implementes an INI file reader/writer.
Copyright © 2019 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.
Package ini provides functions to read/write INI files from/to disc and methods to access the section's key/value pairs.
Index ¶
- Constants
- type TIniList
- func (il *TIniList) AddSectionKey(aSection, aKey, aValue string) bool
- func (il *TIniList) AsBool(aSection, aKey string) (bool, bool)
- func (il *TIniList) AsFloat32(aSection, aKey string) (float32, bool)
- func (il *TIniList) AsFloat64(aSection, aKey string) (float64, bool)
- func (il *TIniList) AsInt(aSection, aKey string) (int, bool)
- func (il *TIniList) AsInt16(aSection, aKey string) (int16, bool)
- func (il *TIniList) AsInt32(aSection, aKey string) (int32, bool)
- func (il *TIniList) AsInt64(aSection, aKey string) (int64, bool)
- func (il *TIniList) AsString(aSection, aKey string) (string, bool)
- func (il *TIniList) Clear() bool
- func (il *TIniList) GetSection(aSection string) *TSection
- func (il *TIniList) HasSection(aSection string) bool
- func (il *TIniList) HasSectionKey(aSection, aKey string) bool
- func (il *TIniList) Len() int
- func (il *TIniList) Load(aFilename string) (*TIniList, error)
- func (il *TIniList) Merge(aINI *TIniList) *TIniList
- func (il *TIniList) RemoveSection(aSection string) bool
- func (il *TIniList) RemoveSectionKey(aSection, aKey string) bool
- func (il *TIniList) Store(aFilename string) (int, error)
- func (il *TIniList) String() (rString string)
- func (il *TIniList) UpdateSectKeyBool(aSection, aKey string, aValue bool) bool
- func (il *TIniList) UpdateSectKeyFloat(aSection, aKey string, aValue float64) bool
- func (il *TIniList) UpdateSectKeyInt(aSection, aKey string, aValue int64) bool
- func (il *TIniList) UpdateSectKeyStr(aSection, aKey, aValue string) bool
- func (il *TIniList) Walk(aFunc TWalkFunc)
- func (il *TIniList) Walker(aWalker TIniWalker)
- type TIniWalker
- type TKeyVal
- type TSection
- func (cs *TSection) AddKey(aKey, aValue string) bool
- func (cs *TSection) AsBool(aKey string) (bool, bool)
- func (cs *TSection) AsFloat32(aKey string) (float32, bool)
- func (cs *TSection) AsFloat64(aKey string) (float64, bool)
- func (cs *TSection) AsInt(aKey string) (int, bool)
- func (cs *TSection) AsInt16(aKey string) (int16, bool)
- func (cs *TSection) AsInt32(aKey string) (int32, bool)
- func (cs *TSection) AsInt64(aKey string) (int64, bool)
- func (cs *TSection) AsString(aKey string) (string, bool)
- func (cs *TSection) Clear() *TSection
- func (cs *TSection) HasKey(aKey string) bool
- func (cs *TSection) IndexOf(aKey string) int
- func (cs *TSection) Len() int
- func (cs *TSection) RemoveKey(aKey string) bool
- func (cs *TSection) String() (rString string)
- func (cs *TSection) UpdateKey(aKey, aValue string) bool
- type TWalkFunc
Constants ¶
const ( // DefSection is the name of the default section in the INI // file which is used when there are key/value pairs in the // file without a preceding section header like `[SectName]`. DefSection = "Default" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TIniList ¶ added in v1.2.0
type TIniList tSections
TIniList is a list of INI sections.
This opaque data structure is filled by e.g. `LoadFile(…)`.
For accessing the sections and key/value pairs it provides the appropriate methods.
func LoadFile ¶
LoadFile reads the given `aFilename` returning the data structure read from the INI file and a possible error condition.
This function reads one line at a time of the INI file skipping both empty lines and comments (identified by '#' or ';' at line start).
`aFilename` is the name of the INI file to read.
func NewSections ¶
func NewSections() *TIniList
NewSections creates a new/empty `IniSections` structure.
func (*TIniList) AddSectionKey ¶ added in v1.2.0
AddSectionKey appends a new key/value pair to `aSection` returning `true` on success or `false` otherwise.
`aSection` name of the INI section to use.
`aKey` the key of the key/value pair to add.
`aValue` the value of the key/value pair to add.
func (*TIniList) AsBool ¶ added in v1.2.0
AsBool returns the value of `aKey` in `aSection` as a boolean value.
If the given aKey in `aSection` doesn't exist then the second (bool) return value will be `false`.
"0", "f", "F", "n" and "N" are considered `false` while "1", "t", "T", "y" and "Y" are considered 'true'; these values will be given in the first result value. All other values will give `false` as the second result value.
This method actually checks only the first character of the key's value so one can write e.g. "false" or "NO" (for a `false` result), or "True" or "yes" (for a 'true' result).
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsFloat32 ¶ added in v1.2.0
AsFloat32 returns the value of `aKey` in `aSection` as a 32bit floating point.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
If s is well-formed and near a valid floating point number, `AsFloat32` returns the nearest floating point number rounded using IEEE754 unbiased rounding.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsFloat64 ¶ added in v1.2.0
AsFloat64 returns the value of `aKey` in `aSection` as a 64bit floating point.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
If s is well-formed and near a valid floating point number, `AsFloat64` returns the nearest floating point number rounded using IEEE754 unbiased rounding.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsInt ¶ added in v1.2.0
AsInt returns the value of `aKey` in `aSection` as an integer.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsInt16 ¶ added in v1.2.0
AsInt16 return the value of `aKey` in `aSection` as a 16bit integer.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsInt32 ¶ added in v1.2.0
AsInt32 return the value of `aKey` in `aSection` as a 32bit integer.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsInt64 ¶ added in v1.2.0
AsInt64 return the value of `aKey` in `aSection` as a 64bit integer.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) AsString ¶ added in v1.2.0
AsString returns the value of `aKey` in `aSection` as a string.
If the given `aKey` in `aSection` doesn't exist then the second (bool) return value will be `false`.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TIniList) Clear ¶ added in v1.2.0
Clear empties the internal data structures.
This method can be called once the program has used the config values stored in the INI file to setup the application. Emptying these data structures should help the garbage collector do release the data not needed anymore.
func (*TIniList) GetSection ¶ added in v1.2.0
GetSection returns the INI section named `aSection`, or `nil` if not found.
func (*TIniList) HasSection ¶ added in v1.2.0
HasSection checks whether the INI data contain `aSection`.
func (*TIniList) HasSectionKey ¶ added in v1.2.0
HasSectionKey checks whether the INI data contain `aSection` with `aKey` returning whether it exists at all.
`aSection` the INI section to lookup.
`aKey` is the key name to lookup in `aSection`.
func (*TIniList) Load ¶ added in v1.2.0
Load reads the given `aFilename` returning the data structure read from the INI file and a possible error condition.
This method reads one line at a time of the INI file skipping both empty lines and comments (identified by '#' or ';' at line start).
`aFilename` is the name of the INI file to read.
func (*TIniList) Merge ¶ added in v1.2.0
Merge copies or merges all INI sections with all key/value pairs into this list.
`aINI` the INI list to merge with this one.
func (*TIniList) RemoveSection ¶ added in v1.2.0
RemoveSection deletes `aSection` from the list of INI sections.
`aSection` the name of the INI section to remove.
func (*TIniList) RemoveSectionKey ¶ added in v1.2.0
RemoveSectionKey removes aKey from aSection.
This method returns 'true' if either `aSection` or `aKey` doesn't exist or if `aKey` in `aSection` was successfully removed, or `false` otherwise.
`aSection` the name of the INI section to use.
`aKey` the name of the key/value pair to remove.
func (*TIniList) Store ¶ added in v1.2.0
Store writes all INI data to `aFilename` returning the number of bytes written and a possible error.
`aFilename` is the name of the INI file to write.
func (*TIniList) String ¶ added in v1.2.0
String returns a string representation of an INI section list.
func (*TIniList) UpdateSectKeyBool ¶ added in v1.2.0
UpdateSectKeyBool replaces the current value of `aKey` in `aSection` by the provided new `aValue` boolean.
If the given `aValue` is 'true' the string "true" is used otherwise the string "false".
`aSection` the name of the INI section to lookup.
`aKey` the name of the key/value pair to use.
`aValue` the boolean value of the key/value pair to update.
func (*TIniList) UpdateSectKeyFloat ¶ added in v1.2.0
UpdateSectKeyFloat replaces the current value of aKey in `aSection` by the provided new `aValue` float.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key/value pair to use.
`aValue` the float64 value of the key/value pair to update.
func (*TIniList) UpdateSectKeyInt ¶ added in v1.2.0
UpdateSectKeyInt replaces the current value of `aKey` in `aSection` by the provided new `aValue` integer.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key/value pair to use.
`aValue` the int64 value of the key/value pair to update.
func (*TIniList) UpdateSectKeyStr ¶ added in v1.2.0
UpdateSectKeyStr replaces the current value of `aKey` in `aSection` by the provided new `aValue` string.
`aSection` the name of the INI section to lookup.
`aKey` the name of the key/value pair to use.
`aValue` the string value of the key/value pair to update.
func (*TIniList) Walk ¶ added in v1.2.0
Walk traverses through all entries in the INI list sections calling `aFunc` for each entry.
`aFunc` is the function called for each key/value pair in all sections.
func (*TIniList) Walker ¶ added in v1.2.0
func (il *TIniList) Walker(aWalker TIniWalker)
Walker traverses through all entries in the INI list sections calling `aWalker` for each entry.
`aWalker` is an object implementing the `TIniWalker` interface.
type TIniWalker ¶
type TIniWalker interface {
Walk(aSection, aKey, aVal string)
}
TIniWalker is used by `Walker()` when visiting an entry in the INI list.
see `Walker()`
type TSection ¶
type TSection []TKeyVal
TSection is a slice of key/value pairs.
func (*TSection) AddKey ¶
AddKey appends a new key/value pair returning `true` on success or `false` otherwise.
If `aKey` is an empty string the method's result will be `false`.
`aKey` the key of the key/value pair to add.
`aValue` the value of the key/value pair to add.
func (*TSection) AsBool ¶
AsBool returns the value of `aKey` in `aSection` as a boolean value.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
"0", "f", "F", "n" and "N" are considered `false` while "1", "t", "T", "y" and "Y" are considered 'true'; these values will be given in the first result value. All other values will give `false` as the second result value.
This method actually checks only the first character of the key's value so one can write e.g. "false" or "NO" (for a `false` result), or "True" or "yes" (for a 'true' result).
`aSection` the name of the INI section to lookup.
`aKey` the name of the key to lookup.
func (*TSection) AsFloat32 ¶
AsFloat32 returns the value of `aKey` as a 32bit floating point.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
If s is well-formed and near a valid floating point number, `AsFloat32` returns the nearest floating point number rounded using IEEE754 unbiased rounding.
`aKey` the name of the key to lookup.
func (*TSection) AsFloat64 ¶
AsFloat64 returns the value of `aKey` as a 64bit floating point.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
If s is well-formed and near a valid floating point number, `AsFloat64` returns the nearest floating point number rounded using IEEE754 unbiased rounding.
`aKey` the name of the key to lookup.
func (*TSection) AsInt ¶
AsInt returns the value of `aKey` as an integer.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
`aKey` the name of the key to lookup.
func (*TSection) AsInt16 ¶
AsInt16 returns the value of `aKey` as a 16bit integer.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
`aKey` the name of the key to lookup.
func (*TSection) AsInt32 ¶
AsInt32 returns the value of `aKey` as a 32bit integer.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
`aKey` the name of the key to lookup.
func (*TSection) AsInt64 ¶
AsInt64 returns the value of `aKey` as a 64bit integer.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
`aKey` the name of the key to lookup.
func (*TSection) AsString ¶
AsString returns the value of `aKey` as a string.
If the given `aKey` doesn't exist then the second (bool) return value will be `false`.
`aKey` the name of the key to lookup.
func (*TSection) HasKey ¶
HasKey returns whether `aKey` exists in this INI section.
`aKey` the key to lookup.
func (*TSection) IndexOf ¶ added in v1.1.0
IndexOf returns the index of `aKey` in this INI section or `-1` if not found.
`aKey` the key to lookup.
func (*TSection) RemoveKey ¶
RemoveKey removes `aKey` from this section.
This method returns 'true' if `aKey` doesn't exist at all, or if `aKey` was successfully removed, or `false` otherwise.
`aKey` the name of the key/value pair to remove.
func (*TSection) String ¶
String returns a string representation of an INI section.
The single key/value pairs are delimited by a linefeed ('\n).
func (*TSection) UpdateKey ¶
UpdateKey replaces the current value of `aKey` by the provided new `aValue`.
In case `aKey` doesn't already exist in the list (and therefor can't be updated) it will be added by calling the `AddKey()` method.
If `aKey` is an empty string the method's result will be `false`.
`aKey` the key of the key/value pair to update.
`aValue` the value of the key/value pair to update.