broker: add Content-Type and DefaultContentType
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		| @@ -45,6 +45,9 @@ type Options struct { | |||||||
|  |  | ||||||
| 	// GracefulTimeout contains time to wait to finish in flight requests | 	// GracefulTimeout contains time to wait to finish in flight requests | ||||||
| 	GracefulTimeout time.Duration | 	GracefulTimeout time.Duration | ||||||
|  |  | ||||||
|  | 	// ContentType will be used if no content-type set when creating message | ||||||
|  | 	ContentType string | ||||||
| } | } | ||||||
|  |  | ||||||
| // NewOptions create new Options | // NewOptions create new Options | ||||||
| @@ -57,14 +60,19 @@ func NewOptions(opts ...Option) Options { | |||||||
| 		Codecs:          make(map[string]codec.Codec), | 		Codecs:          make(map[string]codec.Codec), | ||||||
| 		Tracer:          tracer.DefaultTracer, | 		Tracer:          tracer.DefaultTracer, | ||||||
| 		GracefulTimeout: DefaultGracefulTimeout, | 		GracefulTimeout: DefaultGracefulTimeout, | ||||||
|  | 		ContentType:     DefaultContentType, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, o := range opts { | 	for _, o := range opts { | ||||||
| 		o(&options) | 		o(&options) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return options | 	return options | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // DefaultContentType is the default content-type if not specified | ||||||
|  | var DefaultContentType = "" | ||||||
|  |  | ||||||
| // Context sets the context option | // Context sets the context option | ||||||
| func Context(ctx context.Context) Option { | func Context(ctx context.Context) Option { | ||||||
| 	return func(o *Options) { | 	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 | // PublishOptions struct | ||||||
| type PublishOptions struct { | type PublishOptions struct { | ||||||
| 	// ContentType for message body | 	// ContentType for message body | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user