-
Notifications
You must be signed in to change notification settings - Fork 39
/
config.go
49 lines (46 loc) · 859 Bytes
/
config.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
package fdfs_client
import (
"bufio"
"io"
"os"
"strconv"
"strings"
"runtime"
)
type config struct {
trackerAddr []string
maxConns int
}
func newConfig(configName string) (*config, error) {
config := &config{}
f, err := os.Open(configName)
if err != nil {
return nil, err
}
splitFlag := "\n"
if runtime.GOOS == "windows" {
splitFlag = "\r\n"
}
reader := bufio.NewReader(f)
for {
line, err := reader.ReadString('\n')
line = strings.TrimSuffix(line, splitFlag)
str := strings.SplitN(line, "=", 2)
switch str[0] {
case "tracker_server":
config.trackerAddr = append(config.trackerAddr, str[1])
case "maxConns":
config.maxConns, err = strconv.Atoi(str[1])
if err != nil {
return nil, err
}
}
if err != nil {
if err == io.EOF {
return config, nil
}
return nil, err
}
}
return config, nil
}