-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
36 lines (29 loc) · 845 Bytes
/
example_test.go
File metadata and controls
36 lines (29 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package inifile_test
import (
"fmt"
"os"
"strings"
"github.com/linkdata/inifile"
)
func ExampleParse() {
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"
}