-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
53 lines (44 loc) · 1.29 KB
/
options.go
File metadata and controls
53 lines (44 loc) · 1.29 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
package sqlcommenter
import (
"context"
)
// Option configures commenter.
type Option func(cmt *commenter)
// AttrProvider provides Attrs from context.Context.
type AttrProvider interface {
GetAttrs(context.Context) Attrs
}
// AttrProviderFunc adapts func to AttrProvider.
type AttrProviderFunc func(context.Context) Attrs
// GetAttrs returns Attrs.
func (f AttrProviderFunc) GetAttrs(ctx context.Context) Attrs {
return f(ctx)
}
// WithAttrs configures commenter with Attrs.
func WithAttrs(attrs Attrs) Option {
return func(cmt *commenter) {
cmt.providers = append(cmt.providers, AttrProviderFunc(func(ctx context.Context) Attrs {
return attrs
}))
}
}
// WithAttrPairs configures commenter with attr pairs.
func WithAttrPairs(pairs ...string) Option {
return func(cmt *commenter) {
cmt.providers = append(cmt.providers, AttrProviderFunc(func(ctx context.Context) Attrs {
return AttrPairs(pairs...)
}))
}
}
// WithAttrProvider configures commenter with AttrProvider.
func WithAttrProvider(prov AttrProvider) Option {
return func(cmt *commenter) {
cmt.providers = append(cmt.providers, prov)
}
}
// WithAttrFunc configures commenter with AttrProviderFunc.
func WithAttrFunc(fn AttrProviderFunc) Option {
return func(cmt *commenter) {
cmt.providers = append(cmt.providers, fn)
}
}