https://github.com/mwat56/ini
A Go INI-file reader/writer
https://github.com/mwat56/ini
configuration golang golang-package ini-parser website
Last synced: 5 months ago
JSON representation
A Go INI-file reader/writer
- Host: GitHub
- URL: https://github.com/mwat56/ini
- Owner: mwat56
- License: gpl-3.0
- Created: 2019-05-02T17:24:56.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T17:21:26.000Z (over 1 year ago)
- Last Synced: 2025-03-24T18:31:23.985Z (over 1 year ago)
- Topics: configuration, golang, golang-package, ini-parser, website
- Language: Go
- Size: 247 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# INI
[](https://golang.org/)
[](https://godoc.org/github.com/mwat56/ini/)
[](https://goreportcard.com/report/github.com/mwat56/ini)
[](https://github.com/mwat56/ini/issues?q=is%3Aopen+is%3Aissue)
[](https://github.com/mwat56/ini/)
[](https://github.com/mwat56/ini/tags)
[](https://github.com/mwat56/ini/blob/main/LICENSE)
- [INI](#ini)
- [Purpose](#purpose)
- [Installation](#installation)
- [Usage](#usage)
- [Licence](#licence)
----
## 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](https://godoc.org/github.com/mwat56/ini#TSectionList) to see the numerous methods provided to load, get, set, and update sections and key/value pairs.
## Licence
Copyright © 2019, 2025 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail :
> 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.
----
[](http://www.gnu.org/copyleft/fdl.html)