-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
39 lines (35 loc) · 773 Bytes
/
util.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
package main
import (
"errors"
"strconv"
"time"
"github.com/larspensjo/config"
)
func GenerateId() string {
return strconv.FormatInt(time.Now().UnixNano(), 10)
}
func getConfig(sec string) (map[string]string, error) {
targetConfig := make(map[string]string)
cfg, err := config.ReadDefault("config.ini")
if err != nil {
return targetConfig, err
}
sections := cfg.Sections()
if len(sections) == 0 {
return targetConfig, errors.New("no " + sec + " config")
}
for _, section := range sections {
if section != sec {
continue
}
sectionData, _ := cfg.SectionOptions(section)
for _, key := range sectionData {
value, err := cfg.String(section, key)
if err == nil {
targetConfig[key] = value
}
}
break
}
return targetConfig, nil
}