-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
66 lines (51 loc) · 1.21 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package influxdb
import (
"errors"
"time"
"github.com/luraproject/lura/v2/config"
)
type influxConfig struct {
address string
username string
password string
ttl time.Duration
database string
bufferSize int
}
func configGetter(extraConfig config.ExtraConfig) (influxConfig, error) {
cfg := influxConfig{
ttl: time.Minute,
database: "krakend",
}
castedConfig, ok := extraConfig[Namespace].(map[string]interface{})
if !ok {
return cfg, ErrNoConfig
}
if value, ok := castedConfig["address"].(string); ok {
cfg.address = value
} else {
return cfg, errNoAddress
}
if value, ok := castedConfig["username"].(string); ok {
cfg.username = value
}
if value, ok := castedConfig["password"].(string); ok {
cfg.password = value
}
if value, ok := castedConfig["buffer_size"].(int); ok {
cfg.bufferSize = value
}
if value, ok := castedConfig["ttl"].(string); ok {
ttl, err := time.ParseDuration(value)
if err != nil {
return cfg, err
}
cfg.ttl = ttl
}
if value, ok := castedConfig["db"].(string); ok {
cfg.database = value
}
return cfg, nil
}
var ErrNoConfig = errors.New("unable to load custom config")
var errNoAddress = errors.New("address is required")