-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper-struct.go
More file actions
65 lines (52 loc) · 1.29 KB
/
wrapper-struct.go
File metadata and controls
65 lines (52 loc) · 1.29 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
package wrapperapp
import (
"github.com/vladbpython/wrapperapp/interfaces"
"github.com/vladbpython/wrapperapp/tools"
)
type WrapperStruct struct {
AppName string
Logger interfaces.WrapLoggerInterFace
maxRetries uint
maxWait uint
}
func (s *WrapperStruct) SetAppName(appName string) {
s.AppName = appName
}
func (s *WrapperStruct) GetAppName() string {
return s.AppName
}
func (s *WrapperStruct) SetMaxRetries(num uint) {
if num == 0 {
num = 3
}
s.maxRetries = num
}
func (s *WrapperStruct) SetMaxWait(num uint) {
if num == 0 {
num = 3
}
s.maxWait = num
}
func (s *WrapperStruct) LogDebug(message string) {
s.Logger.Debug(s.AppName, message)
}
func (s *WrapperStruct) LogInfo(message string) {
s.Logger.Info(s.AppName, message)
}
func (s *WrapperStruct) LogError(err error) {
if err != nil {
s.Logger.Error(s.AppName, err)
}
}
func (s *WrapperStruct) LogCriticalError(err error) {
if err != nil {
s.Logger.FatalError(s.AppName, err)
}
}
func (s *WrapperStruct) RetryCallMethod(method interface{}, arguments ...interface{}) {
tools.WrapFuncOnErrorFatal(s.AppName, s.Logger, s.maxRetries, s.maxWait, method, arguments...)
}
func (s *WrapperStruct) LoadSettingFromConfig(config WrapperStructConfig) {
s.SetMaxRetries(config.MaxRetries)
s.SetMaxWait(config.MaxWait)
}