-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
59 lines (51 loc) · 1.49 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
package logger
import (
"errors"
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
)
// setupConfig setups package configuration values for a system
func setupConfig() error {
config := env.GetConfig()
if config == nil {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "6dee39ac-c930-420e-b777-b95f6cab8981", "can't obtain config")
return env.ErrorDispatch(err)
}
err := config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathError,
Value: nil,
Type: env.ConstConfigTypeGroup,
Editor: "",
Options: nil,
Label: "Error",
Description: "error handling settings",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
// Log level
logLevelValidator := func(newValue interface{}) (interface{}, error) {
newLevel := utils.InterfaceToInt(newValue)
if newLevel > 10 || newLevel < 0 {
err := errors.New("'Log level' config value should be between 0 and 10")
return errorLogLevel, env.ErrorDispatch(err)
}
errorLogLevel = newLevel
return errorLogLevel, nil
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathErrorLogLevel,
Value: 5,
Type: env.ConstConfigTypeInteger,
Editor: "integer",
Options: nil,
Label: "Log level",
Description: "errors below specified level will be send to logger service",
Image: "",
}, logLevelValidator)
if err != nil {
return env.ErrorDispatch(err)
}
return nil
}