fatedier 0f1005ff61 using glide | 7 år sedan | |
---|---|---|
.. | ||
LICENSE | 8 år sedan | |
README.md | 8 år sedan | |
ini.go | 8 år sedan | |
ini_linux_test.go | 7 år sedan | |
ini_test.go | 7 år sedan | |
test.ini | 8 år sedan |
INI parsing library for Go (golang).
View the API documentation here.
Parse an INI file:
import "github.com/vaughan0/go-ini"
file, err := ini.LoadFile("myfile.ini")
Get data from the parsed file:
name, ok := file.Get("person", "name")
if !ok {
panic("'name' variable missing from 'person' section")
}
Iterate through values in a section:
for key, value := range file["mysection"] {
fmt.Printf("%s => %s\n", key, value)
}
Iterate through sections in a file:
for name, section := range file {
fmt.Printf("Section name: %s\n", name)
}
INI files are parsed by go-ini line-by-line. Each line may be one of the following:
Properties defined before any section headers are placed in the default section, which has the empty string as it's key.
Example:
# I am a comment
; So am I!
[apples]
colour = red or green
shape = applish
[oranges]
shape = square
colour = blue