-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathini_test.go
More file actions
92 lines (77 loc) · 1.52 KB
/
Copy pathini_test.go
File metadata and controls
92 lines (77 loc) · 1.52 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gini
import (
"fmt"
"log"
"testing"
)
var (
content = `
default = 1
abc = 2
[data]
host = 192.168.0.1
`
)
func Test1(t *testing.T) {
// ini:=New("./conf") 指定目录
ini := New()
err := ini.Load("app.conf")
if err != nil {
log.Fatal(err)
}
// 读取default key
v := ini.Get("app_name")
fmt.Println(v)
ini.Set("http_addr", 9090)
fmt.Println(ini.Get("app_name"))
ini.SectionSet("database", "host", "192.168.0.111")
err = ini.WriteOriginFile()
if err != nil {
log.Fatal(err)
}
ini.ReLoad()
for _, kv := range ini.sections {
for _, item := range kv {
fmt.Println(item.K, item.V)
}
}
//vb := ini.GetBool("session_on")
//fmt.Printf("bool : %#v \n", vb)
//
//vi, _ := ini.GetInt("http_addr")
//fmt.Printf("int : %#v \n", vi)
//
//// 读取指定section的key
//v = ini.SectionGet("file", "include")
//fmt.Printf("value = %s \n", v)
//
////读取所有的section
//sections := ini.GetSections()
//fmt.Printf("sections: %v \n", sections)
//
////读取指定 section的所有key
//keys := ini.GetKeys("")
//for _, item := range keys {
// fmt.Println(item.K, item.V)
//}
//
////读取include文件的配置
//keys = ini.GetKeys("samblog")
//for _, item := range keys {
// fmt.Println(item.K, item.V)
//}
//重写原来的文件
//err = ini.WriteOriginFile()
//if err != nil {
// log.Fatal(err)
//}
//file, err := os.Create("./conf/new.conf")
//if err != nil {
// log.Fatal(err)
//}
//defer file.Close()
//err = ini.Write(file)
//if err != nil {
// log.Fatal(err)
//}
}