-
Notifications
You must be signed in to change notification settings - Fork 15
/
config_util.go
60 lines (48 loc) · 1.29 KB
/
config_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package configutil
import (
"strings"
"github.com/Ptt-official-app/go-pttbbs/types/ansi"
"github.com/spf13/viper"
)
func SetStringConfig(configPrefix string, idx string, orig string) string {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return viper.GetString(idx)
}
func SetBytesConfig(configPrefix string, idx string, orig []byte) []byte {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return []byte(viper.GetString(idx))
}
func SetBoolConfig(configPrefix string, idx string, orig bool) bool {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return viper.GetBool(idx)
}
func SetColorConfig(configPrefix string, idx string, orig string) string {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return ansi.ANSIColor(viper.GetString(idx))
}
func SetIntConfig(configPrefix string, idx string, orig int) int {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return viper.GetInt(idx)
}
func SetDoubleConfig(configPrefix string, idx string, orig float64) float64 {
idx = configPrefix + "." + strings.ToLower(idx)
if !viper.IsSet(idx) {
return orig
}
return viper.GetFloat64(idx)
}