forked from mantzas/patron
-
Notifications
You must be signed in to change notification settings - Fork 67
/
options.go
50 lines (40 loc) · 1.05 KB
/
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
48
49
50
package patron
import (
"errors"
"log/slog"
)
type OptionFunc func(svc *Service) error
// WithSIGHUP adds a custom handler for handling WithSIGHUP.
func WithSIGHUP(handler func()) OptionFunc {
return func(svc *Service) error {
if handler == nil {
return errors.New("provided WithSIGHUP handler was nil")
}
slog.Debug("setting WithSIGHUP handler func")
svc.sighupHandler = handler
return nil
}
}
// WithLogFields options to pass in additional log fields.
func WithLogFields(attrs ...slog.Attr) OptionFunc {
return func(svc *Service) error {
if len(attrs) == 0 {
return errors.New("attributes are empty")
}
for _, attr := range attrs {
if attr.Key == srv || attr.Key == ver || attr.Key == host {
// don't override
continue
}
svc.observabilityCfg.LogConfig.Attributes = append(svc.observabilityCfg.LogConfig.Attributes, attr)
}
return nil
}
}
// WithJSONLogger to use Go's slog package.
func WithJSONLogger() OptionFunc {
return func(svc *Service) error {
svc.observabilityCfg.LogConfig.IsJSON = true
return nil
}
}