-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
61 lines (51 loc) · 1.03 KB
/
utils.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
package cipherPayload
import (
"fmt"
"strings"
"github.com/rs/zerolog/log"
)
func isExist(slice []string, target string) bool {
for _, item := range slice {
if item == target {
return true
}
}
return false
}
func recoveryCatch() {
if r := recover(); r != nil {
log.Debug().Msgf("Recovered in f: %v", r)
}
}
// Logger
type logger interface {
printf(logType string, anything ...interface{})
}
type loggerConfig struct {
isShow bool
}
func newLogger(isShow bool) logger {
return &loggerConfig{
isShow: isShow,
}
}
func (l *loggerConfig) printf(logType string, anything ...interface{}) {
if !l.isShow {
return
}
var logList []string
for _, val := range anything {
valStr := fmt.Sprintf("%v", val)
logList = append(logList, valStr)
}
logHeader := "[CipherPayload]"
logString := strings.Join(logList, " ")
switch logType {
case "error":
log.Error().Msgf("%v %v", logHeader, logString)
case "info":
log.Info().Msgf("%v %v", logHeader, logString)
default:
log.Debug().Msgf("%v %v", logHeader, logString)
}
}