@@ -2,7 +2,6 @@ package harego
22
33import (
44 "context"
5- "errors"
65 "fmt"
76 "time"
87
@@ -20,6 +19,8 @@ type rabbitWrapper struct {
2019}
2120
2221// Channel returns the underlying channel.
22+ //
23+ //nolint:ireturn // This is a wrapper around connection.Channel
2324func (r * rabbitWrapper ) Channel () (Channel , error ) {
2425 return r .Connection .Channel () //nolint:wrapcheck // Okay here.
2526}
@@ -35,28 +36,29 @@ func URLConnector(url string) Connector {
3536 if err != nil {
3637 return nil , fmt .Errorf ("creating a connection to %q: %w" , url , err )
3738 }
39+
3840 return & rabbitWrapper {conn }, nil
3941 }
4042}
4143
42- // AMQPConnector uses r everytime the Client needs a new connection. You should
43- // make sure r keep being alive.
44- func AMQPConnector (r * amqp.Connection ) Connector {
44+ // AMQPConnector uses the amqp connection everytime the Client needs a new connection. You should
45+ // make sure it is kept alive.
46+ func AMQPConnector (amqpConn * amqp.Connection ) Connector {
4547 return func () (RabbitMQ , error ) {
46- if r .IsClosed () {
47- return nil , errors . New ("connection is closed" )
48+ if amqpConn .IsClosed () {
49+ return nil , fmt . Errorf ("connection is closed: %w" , amqp . ErrClosed )
4850 }
49- return & rabbitWrapper {r }, nil
51+
52+ return & rabbitWrapper {amqpConn }, nil
5053 }
5154}
5255
53- // nolint:govet // most likely not an issue, but cleaner this way.
5456type config struct {
5557 workers int
5658 consumerName string
5759 retryDelay time.Duration
5860 logger logr.Logger
59- ctx context.Context
61+ ctx context.Context //nolint:containedctx // Helps us know when the parent is shut down.
6062
6163 global bool
6264
@@ -85,15 +87,20 @@ type config struct {
8587}
8688
8789func defaultConfig () * config {
90+ const (
91+ defaultChannelBufferSize = 10
92+ defaultRetryDelay = 100 * time .Millisecond
93+ )
94+
8895 return & config {
8996 exchName : "default" ,
9097 workers : 1 ,
91- chBuff : 10 ,
98+ chBuff : defaultChannelBufferSize ,
9299 exchType : ExchangeTypeTopic ,
93100 deliveryMode : DeliveryModePersistent ,
94101 durable : true ,
95102 consumerName : internal .GetRandomName (),
96- retryDelay : 100 * time . Millisecond ,
103+ retryDelay : defaultRetryDelay ,
97104 logger : logr .Discard (),
98105 ctx : context .Background (),
99106 }
0 commit comments