-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
49 lines (34 loc) · 1.32 KB
/
doc.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
A golang implemented library to read/write .ini format files.
With this library, you can load the .ini file a string, a byte array, a file and a io.Reader.
import (
ini "github.com/ochinchina/go-ini"
)
func main() {
//load from .ini file
ini := ini.Load( "myfile.ini")
//load from .ini format string
str_data := "[section1]\nkey1=value1\n[section2]\nkey2=value2"
ini = ini.Load( str_data )
//load .ini format byte array
ini = ini.Load( []byte(str_data) )
//load from io.Reader
var reader io.Reader = ...
ini = ini.Load( reader )
//load from multiple source in one Load method
ini = ini.Load( "myfile.ini", reader, str_data, bytes_data )
}
The loaded Ini includes sections, you can access section:
//get all the sections in the .ini
var sections []*Section = ini.Sections()
//get a section by Name
var section *Section = ini.GetSection( sectionName )
Then the key in a section can be accessed by method GetXXX() and GetXXXWithDefault(defValue):
//get the value of key
value, err := section.GetValue( "key1")
value = section.GetValueWithDefault("key1", "")
//get value of key as int
i, err := section.GetInt( "key2" )
i = section.GetIntWithDefault( "key2" )
*/
package ini