-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathini.go
58 lines (44 loc) · 943 Bytes
/
ini.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
50
51
52
53
54
55
56
57
58
package main
import (
"strings"
"github.com/disiqueira/gotree"
"fmt"
)
func iniGet(key string) string {
key = strings.ToLower(key)
names := cfg.SectionStrings()
for _, section := range names[1:] {
if cfg.Section(section).HasKey(key) {
return section
}
}
return ""
}
func iniSet(key, value string) error {
title := strings.Title(value)
key = strings.ToLower(key)
_, err := cfg.Section(title).NewKey(key, "")
return err
}
func iniDelete(key string) bool {
names := cfg.SectionStrings()
for _, section := range names {
if cfg.Section(section).HasKey(key) {
cfg.Section(section).DeleteKey(key)
return true
}
}
return false
}
func iniScanExt() {
names := cfg.SectionStrings()
tree := gotree.New("Rules")
for _, section := range names[1:] {
folder := tree.Add(section)
keys := cfg.Section(section).KeyStrings()
for _, key := range keys {
folder.Add(key)
}
}
fmt.Println(tree.Print())
}