Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Key ¶ added in v1.0.0
Key returns s lowercased (using strings.ToLower) and with whitespace trimmed. This is not full Unicode case folding.
func ParseValue ¶ added in v1.0.0
ParseValue parses a value string from an INI-file, unquoting and removing trailing comments if needed. Parsed values are always valid UTF-8.
Types ¶
type File ¶ added in v1.0.0
A File represents a parsed INI file. Values found outside of a named section are in the "" section.
The map keys are all lowercase and trimmed of whitespace.
The zero value of File is read-only. Initialize with make(File) before calling Set or Section.
func Parse ¶ added in v1.0.0
Parse reads INI data from an io.Reader and returns a new File.
Unquoted values are trimmed of whitespace. Quoted values preserve whitespace inside the quotes. Parsed values are always valid UTF-8. Input should use LF (\n) or CRLF (\r\n) line endings. A trailing CR-only line ending on the final line is tolerated, but bare CR (\r) characters elsewhere are rejected as syntax errors. Lines are limited by bufio.Scanner's default token size (~64 KiB).
If dupKeysJoin is zero, a duplicate key will replace the previous value. If dupKeysJoin is nonzero, a duplicate key will append it's value to the preexisting key's value using dupKeysJoin as a separator.
You are allowed to pass in a nil io.Reader, which results in a nil File and no error.
Example ¶
package main
import (
"fmt"
"os"
"strings"
"github.com/linkdata/inifile"
)
func main() {
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"
func (File) Get ¶ added in v1.0.0
Get looks up a value for a key in a section and returns that value, along with a boolean result similar to a map lookup.
Section and key strings are case-insensitive and ignore leading and trailing whitespace.
func (File) GetDefault ¶ added in v1.0.0
GetDefault calls Get but returns dflt if the section or key was not found.
Section and key strings are case-insensitive and ignore leading and trailing whitespace.
func (File) Section ¶ added in v1.0.0
Section returns a named Section. A Section will be created if one does not already exist for the given name.
Section and key strings are case-insensitive and ignore leading and trailing whitespace.
inif must be initialized with make(File). Calling Section on a nil File panics.
func (File) Set ¶ added in v1.0.0
Set sets the value for a key in a section.
The section is created if needed. The value is stored as-is. Use Parse to apply INI parsing rules (such as trimming unquoted values). If join is nonzero, the value is appended to any pre-existing value using join as the separator.
Section and key strings are case-insensitive and ignore leading and trailing whitespace.
inif must be initialized with make(File). Calling Set on a nil File panics.
type Section ¶ added in v1.0.0
A Section represents a single section of an INI file.
The map keys are all lowercase and trimmed of whitespace.
func (Section) Get ¶ added in v1.0.0
Get looks up a value for a key in a section and returns that value, along with a boolean result similar to a map lookup.
Key strings are case-insensitive and ignore leading and trailing whitespace.
func (Section) GetDefault ¶ added in v1.0.0
GetDefault calls Get but returns dflt if the key was not found.
Key strings are case-insensitive and ignore leading and trailing whitespace.
type SyntaxError ¶ added in v1.0.0
type SyntaxError struct {
Line int // Line number where the error was found
Source string // The contents of the erroneous line, without leading or trailing whitespace
Err error // Optional source error
}
var ErrSyntax SyntaxError
ErrSyntax is returned when there is a syntax error in an INI file.
func (SyntaxError) Error ¶ added in v1.0.0
func (e SyntaxError) Error() string
func (SyntaxError) Is ¶ added in v1.0.0
func (e SyntaxError) Is(target error) bool
func (SyntaxError) Unwrap ¶ added in v1.0.2
func (e SyntaxError) Unwrap() error