/
options.go
37 lines (30 loc) · 880 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
package logging
import (
"context"
"go.uber.org/zap/zapcore"
)
func WithOperationStarted(enable bool) Option {
return func(opts *loggingOptions) {
opts.logRequest = enable
}
}
func WithOperationCompleted(enable bool) Option {
return func(opts *loggingOptions) {
opts.logResponse = enable
}
}
func WithRequestExtractor(extractor func(ctx context.Context, req interface{}) (context.Context, zapcore.ObjectMarshaler, error)) Option {
return func(opts *loggingOptions) {
opts.extractRequest = extractor
}
}
func WithResponseExtractor(extractor func(ctx context.Context, resp interface{}) zapcore.ObjectMarshaler) Option {
return func(opts *loggingOptions) {
opts.extractResponse = extractor
}
}
func WithErrorHandler(handler func(ctx context.Context, err error) []zapcore.Field) Option {
return func(opts *loggingOptions) {
opts.handleError = handler
}
}