mirror of
https://gitee.com/shikong-sk/go-rabbitmq-study
synced 2025-02-23 07:22:15 +08:00
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package types
|
|
|
|
import "github.com/streadway/amqp"
|
|
|
|
type DeclareOptions = []DeclareOptionFunc
|
|
|
|
type DeclareOption struct {
|
|
Name string
|
|
Kind string
|
|
Durable bool
|
|
AutoDelete bool
|
|
Internal bool
|
|
NoWait bool
|
|
Exclusive bool
|
|
Args amqp.Table
|
|
}
|
|
|
|
type DeclareOptionFunc func(option *DeclareOption)
|
|
|
|
func NewExchangeOption(name string, kind string, durable bool, autoDelete bool, internal bool, noWait bool, args amqp.Table) *DeclareOption {
|
|
return &DeclareOption{Name: name, Kind: kind, Durable: durable, AutoDelete: autoDelete, Internal: internal, NoWait: noWait, Args: args}
|
|
}
|
|
|
|
func Name(name string) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Name = name
|
|
}
|
|
}
|
|
|
|
func ExchangeDirectKind() DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Kind = "direct"
|
|
}
|
|
}
|
|
|
|
func Durable(val bool) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Durable = val
|
|
}
|
|
}
|
|
|
|
func AutoDelete(val bool) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.AutoDelete = val
|
|
}
|
|
}
|
|
|
|
func Internal(val bool) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Internal = val
|
|
}
|
|
}
|
|
|
|
func NoWait(val bool) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.NoWait = val
|
|
}
|
|
}
|
|
|
|
func Args(args amqp.Table) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Args = args
|
|
}
|
|
}
|
|
|
|
func QueueExclusive(val bool) DeclareOptionFunc {
|
|
return func(option *DeclareOption) {
|
|
option.Exclusive = val
|
|
}
|
|
}
|
|
|
|
func MergeExchangeOptions(options DeclareOptions) *DeclareOption {
|
|
defaultOption := &DeclareOption{}
|
|
return MergeExchangeOptionsWithDefault(defaultOption, options)
|
|
}
|
|
|
|
func MergeExchangeOptionsWithDefault(defaultOption *DeclareOption, options DeclareOptions) *DeclareOption {
|
|
option := defaultOption
|
|
|
|
for _, exchangeOption := range options {
|
|
exchangeOption(option)
|
|
}
|
|
return option
|
|
}
|