-
Notifications
You must be signed in to change notification settings - Fork 376
/
recommender.go
41 lines (35 loc) · 935 Bytes
/
recommender.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
package apis
import (
"strconv"
"time"
)
func (r Recommender) GetConfigFloat(key string, def float64) (float64, error) {
if value, exists := r.Config[key]; exists {
return strconv.ParseFloat(value, 64)
}
return def, nil
}
func (r Recommender) GetConfigInt(key string, def int64) (int64, error) {
if value, exists := r.Config[key]; exists {
return strconv.ParseInt(value, 10, 64)
}
return def, nil
}
func (r Recommender) GetConfigBool(key string, def bool) (bool, error) {
if value, exists := r.Config[key]; exists {
return strconv.ParseBool(value)
}
return def, nil
}
func (r Recommender) GetConfigString(key string, def string) string {
if value, exists := r.Config[key]; exists {
return value
}
return def
}
func (r Recommender) GetConfigDuration(key string, def time.Duration) (time.Duration, error) {
if value, exists := r.Config[key]; exists {
return time.ParseDuration(value)
}
return def, nil
}