goini

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2018 License: BSD-2-Clause Imports: 6 Imported by: 0

README

goini

Minimal Golang INI parsing function

Usage

Documentation is available via GoDoc.

Description

Sometimes a program needs to parse an INI file. This library reads from either a file or an io.Reader and parses the text into a map[string]map[string]string instance. The default section of an INI file is the General section. Key-Value pairs in the INI text are assigned to the General section until a new section header is read.

Supported Use Cases
Parse
    config, err := goini.Parse(someReader)
    if err != nil {
        panic(err)
    }
    
    for sectionName, sectionMap := range config {
        fmt.Printf("[%s]\n", sectionName)
        for key, value := range sectionMap {
            fmt.Printf("%s = %s\n", key, value)
        }
    }
ParseFile
    config, err := goini.ParseFile(configPathname)
    if err != nil {
        panic(err)
    }
    
    for sectionName, sectionMap := range config {
        fmt.Printf("[%s]\n", sectionName)
        for key, value := range sectionMap {
            fmt.Printf("%s = %s\n", key, value)
        }
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(ior io.Reader) (map[string]map[string]string, error)

Parse reads text from the specified `io.Reader` and parses it into a two-level map. The top level of the map is the section name, and the second layer map is the key-value map for that section.

config, err := goini.Parse(someReader)
if err != nil {
    panic(err)
}

for sectionName, sectionMap := range config {
    fmt.Printf("[%s]\n", sectionName)
    for key, value := range sectionMap {
        fmt.Printf("%s = %s\n", key, value)
    }
}

func ParseFile

func ParseFile(pathname string) (map[string]map[string]string, error)

ParseFile reads text from the file specified by the `pathname` and parses it into a two-level map. The top level of the map is the section name, and the second layer map is the key-value map for that section.

config, err := goini.ParseFile(configPathname)
if err != nil {
    panic(err)
}

for sectionName, sectionMap := range config {
    fmt.Printf("[%s]\n", sectionName)
    for key, value := range sectionMap {
        fmt.Printf("%s = %s\n", key, value)
    }
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL