ini

package module
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: GPL-3.0 Imports: 10 Imported by: 2

README

INI

Golang GoDoc Go Report Issues Size Tag License


Purpose

Over the times several different file formats have been developed just for storing configuration data for some program. While they all may have some merits, for me the two-dimensional INI file format – made popular by the DR-/MS-/PC-DOS and MS-Windows versions in the 80s of the last century – was always sufficient for my needs. This package provides the TSectionList class to read/parse, modify, and write such INI files. It doesn't need any configuration for itself but simply does what it's supposed to do.

Installation

You can use Go to install this package for you:

go get -u github.com/mwat56/ini

Usage

An INI file usually looks like this:

; This is a comment

[aSectionName]
    key1 = value 1
    key2 = value2
    # …

[anotherSection]
    key1 = value1
    key2 = value 2 is \
    really long and\
    spans several lines
    # …

Leading whitespace is ignored, empty lines and those beginning with either a semicolon (;) or a number sign (#) are skipped (and not preserved when overwriting the file). Lines that can't be identified as either a section heading or a key/value pair are silently ignored as well. Quotes and whitespace surrounding a key or a value are ignored.

A line ending with a backslash (\) will be concatenated with the following line (unless that's a comment line). By that mechanism you can use really long values spawning several lines.

You can create a new TSectionList instance by simply calling ini.New(aFilename) and then using the numerous methods (including Store()) of the returned instance.

Note that both, section and key names, are case sensitive to allow for the broadest possible range when naming them. The same is true for the key/value pairs which are, of course, case sensitive. An application using this package, however, is free to interpret the values returned in any way they like.

The configured values can be retrieved from the INI list as any primitive data type calling the appropriate AsXxx() methods.

Please look at the source code documentation to see the numerous methods provided to load, get, set, and update sections and key/value pairs.

Licence

Copyright © 2019, 2024  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 for details.


Documentation

Overview

Package ini implements an INI file reader/writer with methods to read/write INI files from/to disc and methods to access the section's key/value pairs.

Copyright © 2019, 2024  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.

Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany

   All rights reserved
EMail : <support@mwat.de>

Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany

   All rights reserved
EMail : <support@mwat.de>

Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany

   All rights reserved
EMail : <support@mwat.de>

Index

Constants

View Source
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 `[SectionName]`.
	DefSection = `Default`
)

Variables

This section is empty.

Functions

func ReadIniData added in v1.5.0

func ReadIniData(aName string) (*TSection, *TSectionList)

`ReadIniData()` returns the config values read from INI file(s).

The steps here are:
(1) read the local `./.aName.ini`,
(2) read the global `/etc/aName.ini`,
(3) read the user-local `~/.aName.ini`,
(4) read the user-local `~/.config/aName.ini`,
(5) read the `-ini` commandline argument.

This utility function returns the `Default` section of the INI files. It is intended for applications that only use the single default section for its configuration values.

Example:

iniData := ReadIniData("myApp")
fmt.Println(iniData.AsString("", "myKey"))

The function returns a pointer to the 'Default' section of the first INI file that contains it.

Parameters:

`aName` The application's name used as the INI file name

(without `.ini` extension).

Returns:

*TSection: The default section of the INI file. *TSectionList: The list of sections of the INI file.

Types

type TIniWalkFunc added in v1.7.0

type TIniWalkFunc func(aSection, aKey, aVal string)

`TIniWalkFunc()` is used by `Walk()` when visiting an entry in the INI list.

see `Walk()`

type TIniWalker

type TIniWalker interface {
	Walk(aSection, aKey, aVal string)
}

A `TIniWalker` is used by `Walker()` when visiting an entry in the INI list.

see `Walker()`

type TSection

type TSection struct {
	// contains filtered or unexported fields
}

`TSection` is a slice of sorted key/value pairs.

func NewSection added in v1.7.0

func NewSection() *TSection

`NewSection()` returns a new instance of `TSection`.

Returns: - `*TSection`: A new instance of `TSection`.

func (*TSection) AddKey

func (kl *TSection) AddKey(aKey, aValue string) bool

`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`.

Parameters: - `aKey` The key of the key/value pair to add. - `aValue` The value of the key/value pair to add.

Returns: - `bool`: `true` if `aKey` was added successfully, `false` otherwise.

func (*TSection) AsBool

func (kl *TSection) AsBool(aKey string) (bool, bool)

`AsBool()` returns the value of `aKey` 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`, `Y`, `j`, `J`, `o`, `O` are considered `true`; these values will be given in the first return value with the second being `true`. 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).

Parameters: - `aKey` The name of the key to lookup.

Returns: - `bool`: The value of `aKey` a `bool`. - `bool`: `true` if the aKey was found, `false` otherwise. All other values will give `false` as the second return value.

func (*TSection) AsFloat32

func (kl *TSection) AsFloat32(aKey string) (float32, bool)

`AsFloat32()` returns the value of `aKey` as a 32bit floating point.

If the given `aKey` doesn't exist then the second return value will be `false`.

If the string is well-formed and near a valid floating point number, `AsFloat32` returns the nearest floating point number rounded using IEEE754 unbiased rounding.

Parameters: -`aKey` The name of the key to lookup.

Returns: - `float32`: The value of `aKey` as a 32bit floating point. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsFloat64

func (kl *TSection) AsFloat64(aKey string) (float64, bool)

`AsFloat64()` returns the value of `aKey` as a 64bit floating point.

If the given `aKey` doesn't exist then the second return value will be `false`.

If the string is well-formed and near a valid floating point number, `AsFloat64` returns the nearest floating point number rounded using IEEE754 unbiased rounding.

Parameters: - `aKey` the name of the key to lookup.

Returns: - `float64`: The value of `aKey` as a 64bit floating point. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsInt

func (kl *TSection) AsInt(aKey string) (int, bool)

`AsInt()` returns the value of `aKey` as an integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup in the list.

Returns: - `int`: The value of `aKey` as an integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsInt8 added in v1.6.0

func (kl *TSection) AsInt8(aKey string) (int8, bool)

`AsInt8()` returns the value of `aKey` as an 8bit integer.

If the given `aKey` doesn't exist or the key's value is empty then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup in the list.

Returns: - `int8`: The value of `aKey` as an 8bit integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsInt16

func (kl *TSection) AsInt16(aKey string) (int16, bool)

`AsInt16()` returns the value of `aKey` as a 16bit integer.

If the given `aKey` doesn't exist or the key's value is empty then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup in the list.

Returns: - `int16`: The value of `aKey` as a 16bit integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsInt32

func (kl *TSection) AsInt32(aKey string) (int32, bool)

`AsInt32()` returns the value of `aKey` as a 32bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `int32`: The value of `aKey` as a 32bit integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsInt64

func (kl *TSection) AsInt64(aKey string) (int64, bool)

`AsInt64()` returns the value of `aKey` as a 64bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `int64`: The value of `aKey` as a 64bit integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsString

func (kl *TSection) AsString(aKey string) (string, bool)

`AsString()` returns the value of `aKey` as a string.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `string`: The value of `aKey` as a string. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsUInt added in v1.6.0

func (kl *TSection) AsUInt(aKey string) (uint, bool)

`AsUInt()` returns the value of `aKey` as an unsigned integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `uint`: The value of `aKey` as an unsigned integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsUInt8 added in v1.6.0

func (kl *TSection) AsUInt8(aKey string) (uint8, bool)

`AsUInt8()` returns the value of `aKey` as an unsigned 8bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `uint8`: The value of `aKey` as a 8bit unsigned integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsUInt16 added in v1.6.0

func (kl *TSection) AsUInt16(aKey string) (uint16, bool)

`AsUInt16()` returns the value of `aKey` as an unsigned 16bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `uint16`: The value of `aKey` as a 16bit unsigned integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsUInt32 added in v1.6.0

func (kl *TSection) AsUInt32(aKey string) (uint32, bool)

`AsUInt32()` returns the value of `aKey` as an unsigned 32bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `uint32`: The value of `aKey` as a 32bit unsigned integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) AsUInt64 added in v1.6.0

func (kl *TSection) AsUInt64(aKey string) (uint64, bool)

`AsUInt64()` returns the value of `aKey` as an unsigned 64bit integer.

If the given `aKey` doesn't exist then the second return value will be `false`.

Parameters: - `aKey` The name of the key to lookup.

Returns: - `uint64`: The value of `aKey` as a 64bit unsigned integer. - `bool`: `true` if `aKey` was found, `false` otherwise.

func (*TSection) Clear

func (kl *TSection) Clear() *TSection

`Clear()` removes all entries in this INI section.

It returns a pointer to the same section, so that you can chain method calls like this:

kl.Clear().AddKey("key", "value")

Returns: - `TSection`: The current section.

func (*TSection) CompareTo added in v1.7.0

func (kl *TSection) CompareTo(aSection *TSection) bool

`CompareTo()` is used to compare two sections for equality. It takes another `TSection` instance as a parameter and returns a boolean value indicating whether the two sections are equal or not.

If the method iterates over all key-value pairs without finding any differences, it returns `true` indicating that the two sections are equal. If either the respective section's lengths are different, or if at least one of the keyValue pairs are different, the method's result is `false`.

Parameters: - `aSection` The `TSection` instance to compare.

Returns: - `bool`: `true` if `aSection` is equal to this instance, `false` otherwise.

func (*TSection) HasKey

func (kl *TSection) HasKey(aKey string) bool

`HasKey()` returns whether `aKey` exists in this INI section.

Parameters: - `aKey` The key to lookup.

Returns: - `bool`: `true` if `aKey` exists in the section, `false` otherwise.

func (*TSection) Len added in v1.2.0

func (kl *TSection) Len() int

`Len()` counts the number of key/value pairs in this section.

Returns: - `int`: The number of key/value pairs in this section.

func (*TSection) Merge added in v1.7.0

func (kl *TSection) Merge(aSection *TSection) *TSection

`Merge()` merges all section key/value pairs into this section.

The method adds all non-existing key/value pairs from `aSection` to this section and updates all existing keys with the values from `aSection`

Parameters: - `aSection`: The INI section to merge with this section.

Returns: - `TSection`: This section added/updated from `aSection`.

func (*TSection) RemoveKey

func (kl *TSection) RemoveKey(aKey string) bool

`RemoveKey()` removes `aKey` from this section.

This method returns 'true' if `aKey` doesn't exist at all, or if `aKey` was successfully removed, and `false` otherwise.

Parameters: - `aKey` The name of the key/value pair to remove.

Returns: - `bool`: `true` if `aKey` was successfully removed, `false` otherwise.

func (*TSection) Sort added in v1.8.0

func (kl *TSection) Sort() *TSection

`Sort()` sorts the key/value pairs in the section alphabetically by key.

The original map is replaced with the new sorted map.

The method returns a pointer to the same section, so that one can chain method calls like this:

kl.Sort().AddKey("key", "value")

Returns: - *TSection: A pointer to the same section after sorting the key-value pairs.

func (*TSection) String

func (kl *TSection) String() (rString string)

`String()` returns a string representation of the whole INI section.

The single key/value pairs are delimited by a linefeed ('\n).

Returns: - `string`: The string representation of the current section.

func (*TSection) UpdateKey

func (kl *TSection) UpdateKey(aKey, aValue string) (rOK bool)

`UpdateKey()` replaces the current value of `aKey` by the provided new `aValue`.

If `aKey` is an empty string the method's result will be `false`.

Parameters: - `aKey` The key of the key/value pair to update. - `aValue` The value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) UpdateKeyBool added in v1.7.0

func (kl *TSection) UpdateKeyBool(aKey string, aValue bool) bool

`UpdateKeyBool()` replaces the current value of `aKey` by the provided new `aValue` boolean.

If the given `aValue` is `true` then the string "true" is used otherwise the string "false".

Parameters: - `aKey` The name of the key/value pair to use. - `aValue` The boolean value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) UpdateKeyInt added in v1.7.0

func (kl *TSection) UpdateKeyInt(aKey string, aValue int64) bool

`UpdateKeyInt()` replaces the current value of `aKey` by the provided new `aValue` integer.

Parameters: - `aKey` The name of the key/value pair to use. - `aValue` The int64 value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) UpdateKeyStr added in v1.7.0

func (kl *TSection) UpdateKeyStr(aKey, aValue string) bool

`UpdateKeyStr` replaces the current value of `aKey` by the provided new `aValue` string.

Parameters: - `aKey` The name of the key/value pair to use. - `aValue` The string value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) UpdateKeyUInt added in v1.7.0

func (kl *TSection) UpdateKeyUInt(aKey string, aValue uint64) bool

`UpdateKeyUInt()` replaces the current value of `aKey` by the provided new `aValue` unsigned integer.

Parameters: - `aKey` The name of the key/value pair to use. - `aValue` The int64 value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) UpdateSectKeyFloat added in v1.7.0

func (kl *TSection) UpdateSectKeyFloat(aKey string, aValue float64) bool

`UpdateKeyFloat()` replaces the current value of `aKey` by the provided new `aValue` float.

Parameters: - `aKey` The name of the key/value pair to use. - `aValue` The float64 value of the key/value pair to update.

Returns: - `bool`: `true` if `aKey` was updated successfully, `false` otherwise.

func (*TSection) Walk added in v1.7.0

func (kl *TSection) Walk(aFunc TSectionWalkFunc)

`Walk()` traverses through all entries in the section calling `aFunc` for each entry.

Parameters: - `aFunc` The function called for each key/value pair in the sections.

func (*TSection) Walker added in v1.8.0

func (kl *TSection) Walker(aWalker TSectionWalker)

`Walker()` traverses through all entries of current section calling `aWalker` for each entry.

Parameters: - `aWalker` An object implementing the `TSectionWalker` interface.

type TSectionList added in v1.6.0

type TSectionList struct {
	// contains filtered or unexported fields
}

`TSectionList` is a list of INI sections.

This opaque data structure is filled by e.g. `load()`.

For accessing the sections and key/value pairs it provides the appropriate methods.

func NewIni added in v1.7.0

func NewIni(aFilename string) (*TSectionList, error)

`NewIni()` reads the given `aFilename` returning the data structure read from that INI file and a possible error condition.

If `aFilename` is empty, the method returns an empty `TSectionList` and a `fs.ErrNotExist`.

This function reads one line at a time of the INI file skipping both empty lines and comments (identified by '#' or ';' at line start).

Parameters:

`aFilename` The name of the INI file to read.

Returns:

*TSectionList: The list of sections of the INI file.
error: A possible error condition.

func NewSectionList added in v1.7.0

func NewSectionList() *TSectionList

`NewSectionList()` creates a new instance of the `TSectionList`.

This method initializes a new `TSectionList` instance with the default section name.

Returns: - *TSectionList: A new instance of the `TSectionList`.

func (*TSectionList) AddSectionKey added in v1.6.0

func (sl *TSectionList) AddSectionKey(aSection, aKey, aValue string) (rOK bool)

`AddSectionKey()` appends a new key/value pair to `aSection` returning `true` on success or `false` otherwise.

Parameters: - `aSection` The 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.

Returns: - `bool`: `true` on success, of `false` if either `aKey` is empty, or `aSection` can't be found or added.

func (*TSectionList) AsBool added in v1.6.0

func (sl *TSectionList) AsBool(aSection, aKey string) (bool, bool)

`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`, `Y`, `j`, `J`, `o`, `O` 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).

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `bool`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsFloat32 added in v1.6.0

func (sl *TSectionList) AsFloat32(aSection, aKey string) (float32, bool)

`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 the key's value is well-formed and near a valid floating point number, `AsFloat32` returns the nearest floating point number rounded using IEEE754 unbiased rounding.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `float32`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsFloat64 added in v1.6.0

func (sl *TSectionList) AsFloat64(aSection, aKey string) (float64, bool)

`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 (`rOK`) return value will be `false`.

If the key's value is well-formed and near a valid floating point number, `AsFloat64` returns the nearest floating point number rounded using IEEE754 unbiased rounding.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `float64`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsInt added in v1.6.0

func (sl *TSectionList) AsInt(aSection, aKey string) (int, bool)

`AsInt()` returns the value of `aKey` in `aSection` as an integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `int`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsInt8 added in v1.6.0

func (sl *TSectionList) AsInt8(aSection, aKey string) (int8, bool)

`AsInt8()` returns the value of `aKey` in `aSection` as a 8bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `int8`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsInt16 added in v1.6.0

func (sl *TSectionList) AsInt16(aSection, aKey string) (int16, bool)

`AsInt16()` return the value of `aKey` in `aSection` as a 16bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `int16`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsInt32 added in v1.6.0

func (sl *TSectionList) AsInt32(aSection, aKey string) (int32, bool)

`AsInt32()` return the value of `aKey` in `aSection` as a 32bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `int32`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsInt64 added in v1.6.0

func (sl *TSectionList) AsInt64(aSection, aKey string) (int64, bool)

`AsInt64()` return the value of `aKey` in `aSection` as a 64bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `int64`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsString added in v1.6.0

func (sl *TSectionList) AsString(aSection, aKey string) (string, bool)

`AsString()` returns the value of `aKey` in `aSection` as a string.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `string`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsUInt added in v1.6.0

func (sl *TSectionList) AsUInt(aSection, aKey string) (uint, bool)

`AsUInt()` returns the value of `aKey` in `aSection` as an unsigned integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `uint`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsUInt8 added in v1.6.0

func (sl *TSectionList) AsUInt8(aSection, aKey string) (uint8, bool)

`AsUInt8()` returns the value of `aKey` in `aSection` as an unsigned 8bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `uint8`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsUInt16 added in v1.6.0

func (sl *TSectionList) AsUInt16(aSection, aKey string) (uint16, bool)

`AsUInt16()` return the value of `aKey` in `aSection` as an unsigned 16bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `uint16`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsUInt32 added in v1.7.0

func (sl *TSectionList) AsUInt32(aSection, aKey string) (uint32, bool)

`AsUInt32()` return the value of `aKey` in `aSection` as an unsigned 32bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `uint32`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) AsUInt64 added in v1.6.0

func (sl *TSectionList) AsUInt64(aSection, aKey string) (uint64, bool)

`AsUInt64()` return the value of `aKey` in `aSection` as an unsigned 64bit integer.

If the given `aKey` in `aSection` doesn't exist then the second return value will be `false`.

Parameters: - `aSection` the name of the INI section to lookup. - `aKey` The name of the key to lookup.

Returns: - `uint64`: The value associated with `aKey`. - `bool`: `true` if `aKey` was found, or false otherwise.

func (*TSectionList) Clear added in v1.6.0

func (sl *TSectionList) Clear() *TSectionList

`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 to release the data not needed anymore.

Returns: - `*TSectionList`: The return value is the cleared list.

func (*TSectionList) CompareTo added in v1.7.0

func (sl *TSectionList) CompareTo(aINI *TSectionList) bool

`CompareTo()` compares the current `TSectionList` with another `TSectionList`. It checks whether both lists have the same number of sections and whether each section in the current list has the same keys and values as in the other list.

Parameters: - `aINI`: The `TSectionList` to compare with the current one.

Returns: - `bool`: `true` if both lists are equal, `false` otherwise.

func (*TSectionList) Filename added in v1.6.0

func (sl *TSectionList) Filename() string

`Filename()` returns the configured filename of the INI file.

func (*TSectionList) GetSection added in v1.6.0

func (sl *TSectionList) GetSection(aSection string) *TSection

`GetSection()` returns the INI section named `aSection`, or an empty list if not found.

Parameters: - `aSection` The name of the INI section to lookup.

Returns: - `*TSection`: The requested section or an empty if not found.

func (*TSectionList) HasSection added in v1.6.0

func (sl *TSectionList) HasSection(aSection string) (rOK bool)

`HasSection()` checks whether the INI data contain `aSection`.

Parameters: - `aSection` is the name of the INI section to lookup.

Returns: - `bool`: `true` if `aSection` is found, or `false` otherwise.

func (*TSectionList) HasSectionKey added in v1.6.0

func (sl *TSectionList) HasSectionKey(aSection, aKey string) bool

`HasSectionKey()` checks whether the INI data contain `aSection` with `aKey` returning whether it exists at all.

Parameters: - `aSection` The INI section to lookup. - `aKey` The key name to lookup in `aSection`.

Returns: - `bool`: `true` if `aKey` exists, or `false` otherwise.

func (*TSectionList) Len added in v1.6.0

func (sl *TSectionList) Len() int

`Len()` returns the number of INI sections.

It is used to determine the size of the list of sections.

Returns: - `int`: The number of sections in the INI file.

func (*TSectionList) Merge added in v1.6.0

func (sl *TSectionList) Merge(aINI *TSectionList) *TSectionList

`Merge()` copies or merges all INI sections with all key/value pairs into this list.

Parameters: - `aINI` The INI sections to merge with this list.

Returns: - `TSectionList` This sections list merged with the other one.

func (*TSectionList) RemoveSection added in v1.6.0

func (sl *TSectionList) RemoveSection(aSection string) bool

`RemoveSection()` deletes `aSection` from the list of sections.

Parameters: - `aSection` The name of the INI section to remove.

Returns: - `bool`: `true` on success, `false` on failure.

func (*TSectionList) RemoveSectionKey added in v1.6.0

func (sl *TSectionList) RemoveSectionKey(aSection, aKey string) bool

`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.

Parameters: - `aSection` is the name of the INI section to use. - `aKey` The name of the key/value pair to remove.

Returns: - `bool`: `true` on success, `false` on failure.

func (*TSectionList) Sections added in v1.6.0

func (sl *TSectionList) Sections() ([]string, int)

`Sections()` returns a list of section names in the order they appear in the INI file.

The returned list is a slice of strings. The length of the slice is the number of sections in the INI file.

Returns: - `[]string`: A list of section names - `int`: The number of sections in the returned list.

func (*TSectionList) SetFilename added in v1.6.0

func (sl *TSectionList) SetFilename(aFilename string) *TSectionList

`SetFilename()` sets the filename of the INI file to use.

Parameters: - `aFilename` The name to use for the INI file.

func (*TSectionList) Sort added in v1.8.0

func (sl *TSectionList) Sort() *TSectionList

`Sort()` sorts the sections in the order they appear in the INI file.

This method sorts the key/value pairs in each section.

Returns: - `*TSectionList`: The sorted instance of the `TSectionList`.

func (*TSectionList) Store added in v1.6.0

func (sl *TSectionList) Store() (int, error)

`Store()` writes all INI data to the configured filename.

Returns: - `int`: The number of bytes written. - `error`: An possible error during writing the data to file.

func (*TSectionList) String added in v1.6.0

func (sl *TSectionList) String() (rString string)

`String()` returns a string representation of the INI section list.

Returns: - `string`: The string representation of the INI section list.

func (*TSectionList) UpdateSectKeyBool added in v1.6.0

func (sl *TSectionList) UpdateSectKeyBool(aSection, aKey string, aValue bool) bool

`UpdateSectKeyBool()` replaces the current value of `aKey` in `aSection` by the provided new `aValue` boolean.

If the given `aValue` is `true` then the string "True" is used otherwise the string "False".

Parameters: - `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.

Returns: - bool: `true` if the key/value pair was successfully updated, or `false` otherwise.

func (*TSectionList) UpdateSectKeyFloat added in v1.6.0

func (sl *TSectionList) UpdateSectKeyFloat(aSection, aKey string, aValue float64) bool

`UpdateSectKeyFloat()` replaces the current value of `aKey` in `aSection` by the provided new `aValue` float.

Parameters: - `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.

Returns: - bool: `true` if the key/value pair was successfully updated, or `false` otherwise.

func (*TSectionList) UpdateSectKeyInt added in v1.6.0

func (sl *TSectionList) UpdateSectKeyInt(aSection, aKey string, aValue int64) bool

`UpdateSectKeyInt()` replaces the current value of `aKey` in `aSection` by the provided new `aValue` integer.

Parameters: - `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.

Returns: - bool: `true` if the key/value pair was successfully updated, or `false` otherwise.

func (*TSectionList) UpdateSectKeyStr added in v1.6.0

func (sl *TSectionList) UpdateSectKeyStr(aSection, aKey, aValue string) bool

`UpdateSectKeyStr` replaces the current value of `aKey` in `aSection` by the provided new `aValue` string.

Parameters: - `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.

Returns: - bool: `true` if the key/value pair was successfully updated, or `false` otherwise.

func (*TSectionList) UpdateSectKeyUInt added in v1.6.0

func (sl *TSectionList) UpdateSectKeyUInt(aSection, aKey string, aValue uint64) bool

`UpdateSectKeyUInt()` replaces the current value of `aKey` in `aSection` by the provided new `aValue` unsigned integer.

Parameters: - `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.

Returns: - bool: `true` if the key/value pair was successfully updated, or `false` otherwise.

func (*TSectionList) Walk added in v1.6.0

func (sl *TSectionList) Walk(aFunc TIniWalkFunc)

`Walk()` traverses through all entries in the INI list sections calling `aFunc` for each entry.

Parameters: - `aFunc` The function called for each key/value pair in all sections.

func (*TSectionList) Walker added in v1.6.0

func (sl *TSectionList) Walker(aWalker TIniWalker)

`Walker()` traverses through all entries in all INI sections calling `aWalker` for each entry.

Parameters: - `aWalker` An object implementing the `TIniWalker` interface.

type TSectionWalkFunc added in v1.7.0

type TSectionWalkFunc func(aKey, aVal string)

`TSectionWalkFunc()` is used by `Walk()` when visiting the entries in the section.

see `Walk()`

type TSectionWalker added in v1.8.0

type TSectionWalker interface {
	Walk(aKey, aVal string)
}

A `TSectionWalker` is used by `Walker()` when visiting an entry in the section's list.

see `Walker()`

Jump to

Keyboard shortcuts

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