ini

package module
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: GPL-3.0 Imports: 7 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>

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 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 TKeyVal

type TKeyVal struct {
	Key   string
	Value string
}

TKeyVal represents an INI key/value pair.

func (*TKeyVal) AsBool added in v1.5.4

func (kv *TKeyVal) AsBool() (rVal bool)

`AsBool()` returns the value as a boolean value.

`0`, `f`, `F`, `n`, and `N` are considered `false` while `1`, `t`, `T`, `y`, `Y`, `j`, `J`, `o` and `O` are considered `true`; these values will be given in the 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).

func (*TKeyVal) AsFloat32 added in v1.5.4

func (kv *TKeyVal) AsFloat32() (float32, bool)

`AsFloat32()` returns the value of the key/value pair as a 32bit floating point.

If the given `aKey` doesn't exist then the second (`rOK`) 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.

func (*TKeyVal) AsFloat64 added in v1.5.4

func (kv *TKeyVal) AsFloat64() (float64, bool)

`AsFloat64` returns the value of the key/value pair as a 64bit floating point.

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.

func (*TKeyVal) AsInt added in v1.5.4

func (kv *TKeyVal) AsInt() (int, bool)

`AsInt()` returns the value of the key/value pair as an integer.

func (*TKeyVal) AsInt8 added in v1.6.0

func (kv *TKeyVal) AsInt8() (int8, bool)

`AsInt8()` returns the value of the key/value pair as an integer.

func (*TKeyVal) AsInt16 added in v1.5.4

func (kv *TKeyVal) AsInt16() (int16, bool)

`AsInt16()` returns the value of the key/value pair as a 16bit integer.

func (*TKeyVal) AsInt32 added in v1.5.4

func (kv *TKeyVal) AsInt32() (int32, bool)

`AsInt32()` returns the value of the key/value pair as a 32bit integer.

func (*TKeyVal) AsInt64 added in v1.5.4

func (kv *TKeyVal) AsInt64() (int64, bool)

`AsInt64()` returns the value of the key/value pair as a 64bit integer.

func (*TKeyVal) AsString added in v1.5.4

func (kv *TKeyVal) AsString() (string, bool)

`AsString()` returns the value of the key's value as a string.

The second return value will be `true` (it exists for symmetry only).

func (*TKeyVal) AsUInt added in v1.6.0

func (kv *TKeyVal) AsUInt() (uint, bool)

`AsUInt()` returns the value of the key/value pair as an unsigned integer.

func (*TKeyVal) AsUInt8 added in v1.6.0

func (kv *TKeyVal) AsUInt8() (uint8, bool)

`AsUInt8()` returns the value of the key/value pair as an unsigned 8bit integer.

func (*TKeyVal) AsUInt16 added in v1.6.0

func (kv *TKeyVal) AsUInt16() (uint16, bool)

`AsUInt16()` returns the value of the key/value pair as an unsigned 16bit integer.

func (*TKeyVal) AsUInt32 added in v1.6.0

func (kv *TKeyVal) AsUInt32() (uint32, bool)

`AsUInt32()` returns the value of the key/value pair as an unsigned 32bit integer.

func (*TKeyVal) AsUInt64 added in v1.6.0

func (kv *TKeyVal) AsUInt64() (uint64, bool)

`AsUInt64()` returns the value of the key/value pair as an unsigned 64bit integer.

func (*TKeyVal) String

func (kv *TKeyVal) String() string

`String()` returns a string representation of the key/value pair.

The returned string follows the pattern `Key = value`.

func (*TKeyVal) UpdateValue added in v1.5.4

func (kv *TKeyVal) UpdateValue(aValue string) bool

`UpdateValue()` replaces the current value of the key/value pair by the provided new `aValue`.

Parameters:

`aValue` The value of the key/value pair to update.

type TSection

type TSection []TKeyVal

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

func (*TSection) AddKey

func (ks *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 the result of `ks.RemoveKey(aKey)` i.e. usually `true`. If `aKey` already exist its value will be updated by `aValue`. If `aKey` doesn't exist in the section's list a new key/value pair will be appended.

Parameters:

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

func (*TSection) AsBool

func (ks *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`, 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).

Parameters:

`aKey` The name of the key to lookup.

func (*TSection) AsFloat32

func (ks *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.

func (*TSection) AsFloat64

func (ks *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.

func (*TSection) AsInt

func (ks *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.

func (*TSection) AsInt8 added in v1.6.0

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

`AsInt8()` returns the value of `aKey` as an 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.

func (*TSection) AsInt16

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

`AsInt16()` returns the value of `aKey` as a 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.

func (*TSection) AsInt32

func (ks *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.

func (*TSection) AsInt64

func (ks *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.

func (*TSection) AsString

func (ks *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.

func (*TSection) AsUInt added in v1.6.0

func (ks *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.

func (*TSection) AsUInt8 added in v1.6.0

func (ks *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.

func (*TSection) AsUInt16 added in v1.6.0

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

`AsInt16()` 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.

func (*TSection) AsUInt32 added in v1.6.0

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

`AsInt32()` 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.

func (*TSection) AsUInt64 added in v1.6.0

func (ks *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.

func (*TSection) Clear

func (ks *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:

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

This method does not return any error, because it does not perform any I/O operation.

func (*TSection) HasKey

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

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

Parameters:

`aKey` The key to lookup.

Returns:

`true` if aKey exists in the section, false otherwise.

func (*TSection) IndexOf added in v1.1.0

func (ks *TSection) IndexOf(aKey string) int

`IndexOf()` returns the index of `aKey` in this INI section or `-1` if not found.

Parameters:

`aKey` The key to lookup.

func (*TSection) Len added in v1.2.0

func (ks *TSection) Len() int

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

func (*TSection) RemoveKey

func (ks *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.

func (*TSection) String

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

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

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

func (*TSection) UpdateKey

func (ks *TSection) UpdateKey(aKey, aValue string) bool

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

In case `aKey` doesn't already exist in the list (and therefore 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`.

Parameters:

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

type TSectionList added in v1.6.0

type TSectionList tIniSectionsList

`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 New added in v1.3.0

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

`New()` reads the given `aFilename` returning the data structure read from that 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).

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 (*TSectionList) AUInt32 added in v1.6.0

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

`AsUInt32()` 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.

func (*TSectionList) AddSectionKey added in v1.6.0

func (sl *TSectionList) AddSectionKey(aSection, aKey, aValue string) 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.

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.

func (*TSectionList) AsFloat32 added in v1.6.0

func (sl *TSectionList) AsFloat32(aSection, aKey string) (rVal float32, rOK 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.

func (*TSectionList) AsFloat64 added in v1.6.0

func (sl *TSectionList) AsFloat64(aSection, aKey string) (rVal float64, rOK 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.

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.

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.

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.

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.

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.

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.

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

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

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

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.

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.

The return value is the cleared list.

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.

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.

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

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:

rOK: 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:

`aINI` The INI list to merge with this one.

func (*TSectionList) RemoveSection added in v1.6.0

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

`RemoveSection()` deletes `aSection` from the list of INI 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:

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) Store added in v1.6.0

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

`Store()` writes all INI data to the configured filename returning the number of bytes written and a possible error.

func (*TSectionList) String added in v1.6.0

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

String() returns a 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.

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.

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.

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.

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.

func (*TSectionList) Walk added in v1.6.0

func (sl *TSectionList) Walk(aFunc TWalkFunc)

`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 the INI list sections calling `aWalker` for each entry.

Parameters:

`aWalker` An object implementing the `TIniWalker` interface.

type TWalkFunc

type TWalkFunc func(aSection, aKey, aVal string)

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

see `Walk()`

Jump to

Keyboard shortcuts

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