https://github.com/jotaen/genie
Your friendly .ini file parsing library, written in Go.
https://github.com/jotaen/genie
config golang ini library parser
Last synced: 10 days ago
JSON representation
Your friendly .ini file parsing library, written in Go.
- Host: GitHub
- URL: https://github.com/jotaen/genie
- Owner: jotaen
- License: mit
- Created: 2023-02-14T22:42:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-17T22:38:29.000Z (over 3 years ago)
- Last Synced: 2025-02-27T04:48:36.607Z (over 1 year ago)
- Topics: config, golang, ini, library, parser
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Genie 🧞‍♂️
Your friendly .ini config file parser, written in Go.
## Usage
```go
package main
import ("fmt"; "github.com/jotaen/genie")
const iniText = `
# Comment.
key = value
[section1]
foo = bar
test = 123
`
func main() {
data, err := genie.Parse(iniText)
if err != nil {
panic(err)
}
// Access values directly, either from top-level or from section:
fmt.Println(data.Get("key")) // Prints `value`.
fmt.Println(data.GetFromSection("section1", "foo")) // Prints `bar`.
fmt.Println(data.GetFromSection("section1", "test")) // Prints `123`.
// Retrieve all values from a section:
section1 := data.GetSection("section1")
fmt.Println(section1.Get("foo")) // Prints `bar`.
fmt.Println(section1.Get("test")) // Prints `123`.
// Accessing non-existing values returns empty string:
fmt.Println(data.Get("asdfasdf")) // Prints empty string.
fmt.Println(data.GetFromSection("section26487", "bla")) // Prints empty string.
}
```
## Rules
### Entries
- An entry is a key/value pair.
- The delimiter between key and value is the sequence of a `=` character surrounded by a space ` ` character on each side.
- The key itself cannot contain whitespace.
- All what follows behind the delimiter is value-land, including any whitespace, `#`’s, or really whatever.
- The value might be absent, in which case the space behind the `=` may be absent too.
- There is no difference between “absent” value or “empty” value.
- Both the key and the value are case-sensitive.
### Sections
- A label wrapped in square brackets denotes the section for all following entries (until the next section).
- All entries until the first explicit section belong to the top-level section.
- Section names cannot be empty or blank; they are case-sensitive.
### Comments
- If a line starts with `#`, it’s treated as comment and is ignored.
- There generally can’t be trailing comments.
### Whitespace
- Whitespace is a space ` ` or a tab `\t`.
- Lines can never start with whitespace, unless they are all blank.
## License
[MIT](LICENSE.txt)