From a1ee8728add87df52677583b13dacea260bcff80 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 9 May 2025 12:34:46 +0300 Subject: [PATCH] broker: add Content-Type and DefaultContentType Signed-off-by: Vasiliy Tolstov --- broker/options.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/broker/options.go b/broker/options.go index f98e7a62..15fa6857 100644 --- a/broker/options.go +++ b/broker/options.go @@ -45,6 +45,9 @@ type Options struct { // GracefulTimeout contains time to wait to finish in flight requests GracefulTimeout time.Duration + + // ContentType will be used if no content-type set when creating message + ContentType string } // NewOptions create new Options @@ -57,14 +60,19 @@ func NewOptions(opts ...Option) Options { Codecs: make(map[string]codec.Codec), Tracer: tracer.DefaultTracer, GracefulTimeout: DefaultGracefulTimeout, + ContentType: DefaultContentType, } for _, o := range opts { o(&options) } + return options } +// DefaultContentType is the default content-type if not specified +var DefaultContentType = "" + // Context sets the context option func Context(ctx context.Context) Option { return func(o *Options) { @@ -72,6 +80,13 @@ func Context(ctx context.Context) Option { } } +// ContentType used by default if not specified +func ContentType(ct string) Option { + return func(o *Options) { + o.ContentType = ct + } +} + // PublishOptions struct type PublishOptions struct { // ContentType for message body