This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
opts.go
73 lines (55 loc) · 1.76 KB
/
opts.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
// Copyright (c) 2021 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
package redis
import (
"fmt"
"time"
"github.com/sirupsen/logrus"
)
// ClientOpt represents a configuration option to initialize the queue client.
type ClientOpt func(*client) error
// WithAddress sets the Redis address in the queue client.
func WithAddress(address string) ClientOpt {
logrus.Trace("configuring address in redis queue client")
return func(c *client) error {
// check if the address provided is empty
if len(address) == 0 {
return fmt.Errorf("no Redis queue address provided")
}
// set the queue address in the redis client
c.config.Address = address
return nil
}
}
// WithChannels sets the Redis channels in the queue client.
func WithChannels(channels ...string) ClientOpt {
logrus.Trace("configuring channels in redis queue client")
return func(c *client) error {
// check if the channels provided are empty
if len(channels) == 0 {
return fmt.Errorf("no Redis queue channels provided")
}
// set the queue channels in the redis client
c.config.Channels = channels
return nil
}
}
// WithCluster sets the Redis clustering mode in the queue client.
func WithCluster(cluster bool) ClientOpt {
logrus.Trace("configuring clustering mode in redis queue client")
return func(c *client) error {
// set the queue clustering mode in the redis client
c.config.Cluster = cluster
return nil
}
}
// WithTimeout sets the Redis timeout in the queue client.
func WithTimeout(timeout time.Duration) ClientOpt {
logrus.Trace("configuring timeout in redis queue client")
return func(c *client) error {
// set the queue timeout in the redis client
c.config.Timeout = timeout
return nil
}
}