This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
client_options.go
83 lines (72 loc) · 1.9 KB
/
client_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package taskmanager
import (
"context"
zLogger "github.com/mrz1836/go-logger"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/vmihailenco/taskq/v3"
)
// ClientOps allow functional options to be supplied
// that overwrite default client options.
type ClientOps func(c *clientOptions)
// defaultClientOptions will return an clientOptions struct with the default settings
//
// Useful for starting with the default and then modifying as needed
func defaultClientOptions() *clientOptions {
// Set the default options
return &clientOptions{
debug: false,
engine: Empty,
newRelicEnabled: false,
taskq: &taskqOptions{
tasks: make(map[string]*taskq.Task),
},
}
}
// GetTxnCtx will check for an existing transaction
func (c *Client) GetTxnCtx(ctx context.Context) context.Context {
if c.options.newRelicEnabled {
txn := newrelic.FromContext(ctx)
if txn != nil {
ctx = newrelic.NewContext(ctx, txn)
}
}
return ctx
}
// WithNewRelic will enable the NewRelic wrapper
func WithNewRelic() ClientOps {
return func(c *clientOptions) {
c.newRelicEnabled = true
}
}
// WithDebugging will enable debugging mode
func WithDebugging() ClientOps {
return func(c *clientOptions) {
c.debug = true
}
}
// WithTaskQ will use the TaskQ engine
func WithTaskQ(config *taskq.QueueOptions, factory Factory) ClientOps {
return func(c *clientOptions) {
if config != nil && !factory.IsEmpty() {
c.engine = TaskQ
c.taskq.config = config
c.taskq.factoryType = factory
}
}
}
// WithLogger will set the custom logger interface
func WithLogger(customLogger zLogger.GormLoggerInterface) ClientOps {
return func(c *clientOptions) {
if customLogger != nil {
c.logger = customLogger
}
}
}
// WithCronService will set the cron service
func WithCronService(cronService CronService) ClientOps {
return func(c *clientOptions) {
if cronService != nil {
c.cronService = cronService
}
}
}