diff --git a/broker/broker.go b/broker/broker.go index 3664433a..582d6deb 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -41,7 +41,7 @@ type Broker interface { // Disconnect disconnect from broker Disconnect(ctx context.Context) error // NewMessage create new broker message to publish. - NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...PublishOption) (Message, error) + NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...MessageOption) (Message, error) // Publish message to broker topic Publish(ctx context.Context, topic string, messages ...Message) error // Subscribe subscribes to topic message via handler diff --git a/broker/context.go b/broker/context.go index 08fe42de..b9fe5af2 100644 --- a/broker/context.go +++ b/broker/context.go @@ -42,9 +42,9 @@ func SetSubscribeOption(k, v interface{}) SubscribeOption { } } -// SetPublishOption returns a function to setup a context with given value -func SetPublishOption(k, v interface{}) PublishOption { - return func(o *PublishOptions) { +// SetMessageOption returns a function to setup a context with given value +func SetMessageOption(k, v interface{}) MessageOption { + return func(o *MessageOptions) { if o.Context == nil { o.Context = context.Background() } diff --git a/broker/memory/memory.go b/broker/memory/memory.go index 305c729e..f4e25e65 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -32,7 +32,7 @@ type memoryMessage struct { ctx context.Context body []byte hdr metadata.Metadata - opts broker.PublishOptions + opts broker.MessageOptions } func (m *memoryMessage) Ack() error { @@ -157,8 +157,8 @@ func (b *Broker) Init(opts ...broker.Option) error { return nil } -func (b *Broker) NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...broker.PublishOption) (broker.Message, error) { - options := broker.NewPublishOptions(opts...) +func (b *Broker) NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...broker.MessageOption) (broker.Message, error) { + options := broker.NewMessageOptions(opts...) if options.ContentType == "" { options.ContentType = b.opts.ContentType } diff --git a/broker/memory/memory_test.go b/broker/memory/memory_test.go index 2d2fd4de..9e85bf70 100644 --- a/broker/memory/memory_test.go +++ b/broker/memory/memory_test.go @@ -49,7 +49,7 @@ func TestMemoryBroker(t *testing.T) { "id", fmt.Sprintf("%d", i), ), []byte(`"hello world"`), - broker.PublishContentType("application/octet-stream"), + broker.MessageContentType("application/octet-stream"), ) if err != nil { t.Fatal(err) diff --git a/broker/noop.go b/broker/noop.go index d1d5e12d..77416397 100644 --- a/broker/noop.go +++ b/broker/noop.go @@ -99,7 +99,7 @@ type noopMessage struct { ctx context.Context body []byte hdr metadata.Metadata - opts PublishOptions + opts MessageOptions } func (m *noopMessage) Ack() error { @@ -126,8 +126,8 @@ func (m *noopMessage) Unmarshal(dst interface{}, opts ...codec.Option) error { return m.c.Unmarshal(m.body, dst) } -func (b *NoopBroker) NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...PublishOption) (Message, error) { - options := NewPublishOptions(opts...) +func (b *NoopBroker) NewMessage(ctx context.Context, hdr metadata.Metadata, body interface{}, opts ...MessageOption) (Message, error) { + options := NewMessageOptions(opts...) if options.ContentType == "" { options.ContentType = b.opts.ContentType } diff --git a/broker/options.go b/broker/options.go index 15fa6857..2c6a58c0 100644 --- a/broker/options.go +++ b/broker/options.go @@ -87,8 +87,8 @@ func ContentType(ct string) Option { } } -// PublishOptions struct -type PublishOptions struct { +// MessageOptions struct +type MessageOptions struct { // ContentType for message body ContentType string // BodyOnly flag says the message contains raw body bytes and don't need @@ -98,9 +98,9 @@ type PublishOptions struct { Context context.Context } -// NewPublishOptions creates PublishOptions struct -func NewPublishOptions(opts ...PublishOption) PublishOptions { - options := PublishOptions{ +// NewMessageOptions creates MessageOptions struct +func NewMessageOptions(opts ...MessageOption) MessageOptions { + options := MessageOptions{ Context: context.Background(), } for _, o := range opts { @@ -128,19 +128,19 @@ type SubscribeOptions struct { // Option func type Option func(*Options) -// PublishOption func -type PublishOption func(*PublishOptions) +// MessageOption func +type MessageOption func(*MessageOptions) -// PublishContentType sets message content-type that used to Marshal -func PublishContentType(ct string) PublishOption { - return func(o *PublishOptions) { +// MessageContentType sets message content-type that used to Marshal +func MessageContentType(ct string) MessageOption { + return func(o *MessageOptions) { o.ContentType = ct } } -// PublishBodyOnly publish only body of the message -func PublishBodyOnly(b bool) PublishOption { - return func(o *PublishOptions) { +// MessageBodyOnly publish only body of the message +func MessageBodyOnly(b bool) MessageOption { + return func(o *MessageOptions) { o.BodyOnly = b } }