-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
59 lines (45 loc) · 1.22 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 zlogres
import (
"github.com/gofiber/fiber/v2"
)
type Config struct {
// Optional. Default: nil
Next func(c *fiber.Ctx) bool
// Optional. Default: "requestid"
RequestIDContextKey string
// Optional. Default: "info"
LogLevel string
// Optional. Default: "micro". Possible Value: ["nano", "micro", "milli"]
ElapsedTimeUnit string
// Optional. Default: "message". Use ContextMessageKey by set `c.Locals("message", "WHATEVER_MESSAGE")`
ContextMessageKey string
}
var ConfigDefault = Config{
Next: nil,
RequestIDContextKey: "requestid",
LogLevel: "info",
ElapsedTimeUnit: "micro",
ContextMessageKey: "message",
}
func configDefault(config ...Config) Config {
// Return default config if nothing provided
if len(config) < 1 {
return ConfigDefault
}
// Override default config
cfg := config[0]
// set default
if cfg.RequestIDContextKey == "" {
cfg.RequestIDContextKey = ConfigDefault.RequestIDContextKey
}
if cfg.LogLevel == "" {
cfg.LogLevel = ConfigDefault.LogLevel
}
if cfg.ElapsedTimeUnit == "" {
cfg.ElapsedTimeUnit = ConfigDefault.ElapsedTimeUnit
}
if cfg.ContextMessageKey == "" {
cfg.ContextMessageKey = ConfigDefault.ContextMessageKey
}
return cfg
}