Skip to content

Commit

Permalink
add shortcuts for declaring bunch of exchanges and queues
Browse files Browse the repository at this point in the history
  • Loading branch information
vetcher committed Mar 26, 2018
1 parent 3231a4b commit fa39a87
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ func LongExchange(name string) Exchange {
}
}

type Exchanges []Exchange

func (e Exchanges) declare(c *Client) {
for i := range e {
if e[i].Name == "" {
panic("exchange name can't be empty")
}
c.exchanges = append(c.exchanges, e[i])
}
}

// PersistentExchanges allow you to declare a bunch of exchanges with given names.
func PersistentExchanges(names ...string) (e Exchanges) {
for i := range names {
e = append(e, LongExchange(names[i]))
}
return
}

type Queue struct {
Name string
Durable bool
Expand All @@ -187,7 +206,7 @@ type Queue struct {
Args amqp.Table
}

// LongExchange is a common way to declare queue with given name.
// LongQueue is a common way to declare queue with given name.
func LongQueue(name string) Queue {
return Queue{
Name: name,
Expand All @@ -203,6 +222,25 @@ func (q Queue) declare(c *Client) {
c.queues = append(c.queues, q)
}

type Queues []Queue

func (q Queues) declare(c *Client) {
for i := range q {
if q[i].Name == "" {
panic("queue name can't be empty")
}
c.queues = append(c.queues, q[i])
}
}

// PersistentQueues allow you to declare a bunch of queues with given names.
func PersistentQueues(names ...string) (e Queues) {
for i := range names {
e = append(e, LongQueue(names[i]))
}
return
}

// Binding is used for bind exchange and queue.
type Binding struct {
Exchange string
Expand Down

0 comments on commit fa39a87

Please sign in to comment.