Skip to content

Commit 22facb5

Browse files
committed
Copy default options to not change it
1 parent aeee45d commit 22facb5

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

consume.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func NewConsumer(
5454
optionFuncs ...func(*ConsumerOptions),
5555
) (*Consumer, error) {
5656
defaultOptions := getDefaultConsumerOptions(queue)
57-
options := &defaultOptions
57+
options := defaultOptions
5858
for _, optionFunc := range optionFuncs {
59-
optionFunc(options)
59+
optionFunc(&options)
6060
}
6161

6262
if conn.connectionManager == nil {
@@ -73,14 +73,14 @@ func NewConsumer(
7373
chanManager: chanManager,
7474
reconnectErrCh: reconnectErrCh,
7575
closeConnectionToManagerCh: closeCh,
76-
options: *options,
76+
options: options,
7777
isClosedMux: &sync.RWMutex{},
7878
isClosed: false,
7979
}
8080

8181
err = consumer.startGoroutines(
8282
handler,
83-
*options,
83+
options,
8484
)
8585
if err != nil {
8686
return nil, err
@@ -91,7 +91,7 @@ func NewConsumer(
9191
consumer.options.Logger.Infof("successful consumer recovery from: %v", err)
9292
err = consumer.startGoroutines(
9393
handler,
94-
*options,
94+
options,
9595
)
9696
if err != nil {
9797
consumer.options.Logger.Fatalf("error restarting consumer goroutines after cancel or close: %v", err)

publish.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ type PublisherConfirmation []*amqp.DeferredConfirmation
6969
// will fail with an error when the server is requesting a slowdown
7070
func NewPublisher(conn *Conn, optionFuncs ...func(*PublisherOptions)) (*Publisher, error) {
7171
defaultOptions := getDefaultPublisherOptions()
72-
options := &defaultOptions
72+
options := defaultOptions
7373
for _, optionFunc := range optionFuncs {
74-
optionFunc(options)
74+
optionFunc(&options)
7575
}
7676

7777
if conn.connectionManager == nil {
@@ -96,7 +96,7 @@ func NewPublisher(conn *Conn, optionFuncs ...func(*PublisherOptions)) (*Publishe
9696
handlerMux: &sync.Mutex{},
9797
notifyReturnHandler: nil,
9898
notifyPublishHandler: nil,
99-
options: *options,
99+
options: options,
100100
}
101101

102102
err = publisher.startup()

publisher_options.go

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func WithPublisherOptionsExchangeName(name string) func(*PublisherOptions) {
5959
options.ExchangeName = name
6060
}
6161
}
62+
func WithPublisherOptionsConfirmMode(confirm bool) func(*PublisherOptions) {
63+
return func(options *PublisherOptions) {
64+
options.ConfirmMode = confirm
65+
}
66+
}
6267

6368
// WithPublisherOptionsExchangeKind ensures the queue is a durable queue
6469
func WithPublisherOptionsExchangeKind(kind string) func(*PublisherOptions) {

0 commit comments

Comments
 (0)