https://github.com/linkdata/inifile
Simple INI file reader
https://github.com/linkdata/inifile
ini inifile
Last synced: 2 months ago
JSON representation
Simple INI file reader
- Host: GitHub
- URL: https://github.com/linkdata/inifile
- Owner: linkdata
- License: mit
- Created: 2023-02-24T05:43:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T06:09:50.000Z (about 1 year ago)
- Last Synced: 2025-03-12T09:14:13.122Z (3 months ago)
- Topics: ini, inifile
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/linkdata/inifile/actions/workflows/go.yml)
[](https://coveralls.io/github/linkdata/inifile?branch=main)
[](https://goreportcard.com/report/github.com/linkdata/inifile)
[](https://godoc.org/github.com/linkdata/inifile)# inifile
Simple INI file reader.
Section and key names are case-insensitive and ignore leading and trailing whitespace.
Supports line comments, trailing comments and quoted values.
Keys appearing more than once will either replace previous values or append to them with a separator.
```go
func ExampleParse() {
const initext = `
# comments start with a hash
; or a semicolon# global keys are in the unnamed (empty string) section
Username = " user name " # values can be quoted preserve whitespace or embed quotes# section names are case insensitive and ignores leading and trailing whitespace
[ HTTP ]
port = 8080 # keys and values are stripped of leading and trailing whitespace
port=8081 # keys appearing more than once either append or replace values
`inif, err := inifile.Parse(strings.NewReader(initext), ',')
if err != nil {
fmt.Fprint(os.Stderr, err)
}
username, _ := inif.Get("", "username")
ports, _ := inif.Get("http", "port")fmt.Printf("%q\n%q\n", username, ports)
// Output:
// " user name "
// "8080,8081"
}
```