/
options.go
47 lines (40 loc) · 933 Bytes
/
options.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
package http_middleware
// LogOption is an option for a request logger.
type LogOption func(*options)
// RequestFilter returns false if the request should be filtered out and true otherwise
type RequestFilter func(url string) bool
// ExcludeURLs returns a RequestFilter that only logs requests for URLs in the urls parameter
func ExcludeURLs(urls ...string) RequestFilter {
return func(url string) bool {
for _, u := range urls {
if url == u {
return false
}
}
return true
}
}
func WithLogBody(b bool) LogOption {
return func(o *options) {
o.logBody = b
}
}
func SkipURL(urls ...string) LogOption {
return func(o *options) {
o.skippedURLs = append(o.skippedURLs, urls...)
}
}
var defaultSkippedURLs = []string{
"/metrics",
"/healthz",
"/ok",
"/shutdownz",
"/version",
"/",
}
type options struct {
filters []RequestFilter
headersToLog []string
logBody bool
skippedURLs []string
}