-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
71 lines (50 loc) · 1.09 KB
/
Copy pathconfig.go
File metadata and controls
71 lines (50 loc) · 1.09 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
package main
import (
"os"
"strconv"
"strings"
"time"
)
type configType struct {
tcpBind string
dirs []string
shortPoll time.Duration
longPoll time.Duration
}
var (
config configType
)
func configFromEnv() configType {
nodirs := []string{}
config.tcpBind = getEnvString("HDDPROXY_TCP_BIND", "127.0.0.1:8080")
sep := getEnvString("HDDPROXY_DIRS_SEP", ":")
config.dirs = getEnvStrings("HDDPROXY_DIRS", nodirs, sep)
sp := getEnvInt("HDDPROXY_SHORTPOLL", 1)
lp := getEnvInt("HDDPROXY_LONGPOLL", 5)
config.shortPoll = time.Duration(sp) * time.Second
config.longPoll = time.Duration(lp) * time.Second
return config
}
func getEnvString(varname, def string) string {
if v := os.Getenv(varname); v != "" {
return v
}
return def
}
func getEnvInt(varname string, def int) int {
if v := os.Getenv(varname); v != "" {
i, err := strconv.Atoi(v)
if err != nil {
return def
}
return i
}
return def
}
func getEnvStrings(varname string, def []string, sep string) []string {
if v := os.Getenv(varname); v != "" {
ar := strings.Split(v, sep)
return ar
}
return def
}