Skip to content

Commit

Permalink
fix: pass shuffle param to StaticResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
wzy9607 committed Jul 2, 2024
1 parent ef6a380 commit 37ae91e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/rand"

amqp "github.com/rabbitmq/amqp091-go"

"github.com/wagslane/go-rabbitmq/internal/connectionmanager"
)

Expand All @@ -26,16 +27,16 @@ type Config amqp.Config
type Resolver = connectionmanager.Resolver

type StaticResolver struct {
urls []string
shuffe bool
urls []string
shuffle bool
}

func (r *StaticResolver) Resolve() ([]string, error) {
// TODO: move to slices.Clone when supported Go versions > 1.21
var urls []string
urls = append(urls, r.urls...)

if r.shuffe {
if r.shuffle {
rand.Shuffle(len(urls), func(i, j int) {
urls[i], urls[j] = urls[j], urls[i]
})
Expand All @@ -44,7 +45,7 @@ func (r *StaticResolver) Resolve() ([]string, error) {
}

func NewStaticResolver(urls []string, shuffle bool) *StaticResolver {
return &StaticResolver{urls: urls}
return &StaticResolver{urls: urls, shuffle: shuffle}
}

// NewConn creates a new connection manager
Expand Down

0 comments on commit 37ae91e

Please sign in to comment.