This repository was archived by the owner on May 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
70 lines (64 loc) · 1.31 KB
/
Copy pathconfig.go
File metadata and controls
70 lines (64 loc) · 1.31 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
66
67
68
69
70
package logger
import (
"github.com/gofiber/fiber/v2"
"golang.org/x/exp/slog"
)
const (
RefererTag = "referer"
UserAgentTag = "user_agent"
IPTag = "ip"
IPsTag = "ips"
LatencyTag = "latency"
LatencyHumanTag = "latency_human"
StatusTag = "status"
PathTag = "path"
UrlTag = "url"
MethodTag = "method"
BodyTag = "body"
BytesReceivedTag = "bytes_received"
BytesSentTag = "bytes_sent"
RequestHeadersTag = "request_headers"
QueryStringTag = "query_string"
)
type (
CustomFunc func(*fiber.Ctx, *slog.Record, error)
Config struct {
Filter func(*fiber.Ctx) bool
CustomAttr []CustomFunc
BuiltinAttrs []string
Logger *slog.Logger
}
)
var defaultConfig = Config{
BuiltinAttrs: []string{
RefererTag,
UserAgentTag,
IPTag,
IPsTag,
LatencyTag,
LatencyHumanTag,
StatusTag,
PathTag,
UrlTag,
MethodTag,
BodyTag,
BytesReceivedTag,
BytesSentTag,
RequestHeadersTag,
QueryStringTag,
},
Logger: slog.Default(),
}
func configDefault(config ...Config) Config {
if len(config) < 1 {
return defaultConfig
}
cfg := config[0]
if cfg.BuiltinAttrs == nil {
cfg.BuiltinAttrs = defaultConfig.BuiltinAttrs
}
if cfg.Logger == nil {
cfg.Logger = defaultConfig.Logger
}
return cfg
}