Skip to content

Commit c90b3b3

Browse files
committed
Refactor exchange type
It had a wrapper struct. It's simpler to use the exchange type directly
1 parent 771249c commit c90b3b3

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

pkg/rabbitmqamqp/amqp_exchange.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rabbitmqamqp
33
import (
44
"context"
55
"errors"
6+
67
"github.com/Azure/go-amqp"
78
)
89

@@ -23,14 +24,14 @@ type AmqpExchange struct {
2324
management *AmqpManagement
2425
arguments map[string]any
2526
isAutoDelete bool
26-
exchangeType ExchangeType
27+
exchangeType TExchangeType
2728
}
2829

2930
func newAmqpExchange(management *AmqpManagement, name string) *AmqpExchange {
3031
return &AmqpExchange{management: management,
3132
name: name,
3233
arguments: make(map[string]any),
33-
exchangeType: ExchangeType{Type: Direct},
34+
exchangeType: Direct,
3435
}
3536
}
3637

@@ -46,7 +47,7 @@ func (e *AmqpExchange) Declare(ctx context.Context) (*AmqpExchangeInfo, error) {
4647
kv := make(map[string]any)
4748
kv["auto_delete"] = e.isAutoDelete
4849
kv["durable"] = true
49-
kv["type"] = e.exchangeType.String()
50+
kv["type"] = string(e.exchangeType)
5051
if e.arguments != nil {
5152
kv["arguments"] = e.arguments
5253
}
@@ -78,14 +79,14 @@ func (e *AmqpExchange) Delete(ctx context.Context) error {
7879
return err
7980
}
8081

81-
func (e *AmqpExchange) ExchangeType(exchangeType ExchangeType) {
82-
if len(exchangeType.Type) > 0 {
82+
func (e *AmqpExchange) ExchangeType(exchangeType TExchangeType) {
83+
if len(exchangeType) > 0 {
8384
e.exchangeType = exchangeType
8485
}
8586
}
8687

8788
func (e *AmqpExchange) GetExchangeType() TExchangeType {
88-
return e.exchangeType.Type
89+
return e.exchangeType
8990
}
9091

9192
func (e *AmqpExchange) Name() string {

pkg/rabbitmqamqp/entities.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,11 @@ const (
350350
Headers TExchangeType = "headers"
351351
)
352352

353-
type ExchangeType struct {
354-
Type TExchangeType
355-
}
356-
357-
func (e ExchangeType) String() string {
358-
return string(e.Type)
359-
}
360-
361353
// IExchangeSpecification represents the specification of an exchange
362354
type IExchangeSpecification interface {
363355
name() string
364356
isAutoDelete() bool
365-
exchangeType() ExchangeType
357+
exchangeType() TExchangeType
366358
arguments() map[string]any
367359
}
368360

@@ -380,8 +372,8 @@ func (d *DirectExchangeSpecification) isAutoDelete() bool {
380372
return d.IsAutoDelete
381373
}
382374

383-
func (d *DirectExchangeSpecification) exchangeType() ExchangeType {
384-
return ExchangeType{Type: Direct}
375+
func (d *DirectExchangeSpecification) exchangeType() TExchangeType {
376+
return Direct
385377
}
386378

387379
func (d *DirectExchangeSpecification) arguments() map[string]any {
@@ -402,8 +394,8 @@ func (t *TopicExchangeSpecification) isAutoDelete() bool {
402394
return t.IsAutoDelete
403395
}
404396

405-
func (t *TopicExchangeSpecification) exchangeType() ExchangeType {
406-
return ExchangeType{Type: Topic}
397+
func (t *TopicExchangeSpecification) exchangeType() TExchangeType {
398+
return Topic
407399
}
408400

409401
func (t *TopicExchangeSpecification) arguments() map[string]any {
@@ -424,8 +416,8 @@ func (f *FanOutExchangeSpecification) isAutoDelete() bool {
424416
return f.IsAutoDelete
425417
}
426418

427-
func (f *FanOutExchangeSpecification) exchangeType() ExchangeType {
428-
return ExchangeType{Type: FanOut}
419+
func (f *FanOutExchangeSpecification) exchangeType() TExchangeType {
420+
return FanOut
429421
}
430422

431423
func (f *FanOutExchangeSpecification) arguments() map[string]any {
@@ -446,8 +438,8 @@ func (h *HeadersExchangeSpecification) isAutoDelete() bool {
446438
return h.IsAutoDelete
447439
}
448440

449-
func (h *HeadersExchangeSpecification) exchangeType() ExchangeType {
450-
return ExchangeType{Type: Headers}
441+
func (h *HeadersExchangeSpecification) exchangeType() TExchangeType {
442+
return Headers
451443
}
452444

453445
func (h *HeadersExchangeSpecification) arguments() map[string]any {
@@ -469,8 +461,8 @@ func (c *CustomExchangeSpecification) isAutoDelete() bool {
469461
return c.IsAutoDelete
470462
}
471463

472-
func (c *CustomExchangeSpecification) exchangeType() ExchangeType {
473-
return ExchangeType{Type: TExchangeType(c.ExchangeTypeName)}
464+
func (c *CustomExchangeSpecification) exchangeType() TExchangeType {
465+
return TExchangeType(c.ExchangeTypeName)
474466
}
475467

476468
func (c *CustomExchangeSpecification) arguments() map[string]any {

0 commit comments

Comments
 (0)