1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-08 14:10:05 +00:00
cloudkeys-go/vendor/github.com/vaughan0/go-ini
2016-05-13 17:29:06 +02:00
..
ini.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
ini_linux_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
ini_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
LICENSE Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
README.md Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
test.ini Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00

go-ini

INI parsing library for Go (golang).

View the API documentation here.

Usage

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)
}

File Format

INI files are parsed by go-ini line-by-line. Each line may be one of the following:

  • A section definition: [section-name]
  • A property: key = value
  • A comment: #blahblah or ;blahblah
  • Blank. The line will be ignored.

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