codec: add ability to pass codec options
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package codec
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
@@ -19,6 +21,10 @@ type Options struct {
|
||||
Tracer tracer.Tracer
|
||||
// MaxMsgSize specifies max messages size that reads by codec
|
||||
MaxMsgSize int
|
||||
// TagName specifies tag name in struct to control codec
|
||||
TagName string
|
||||
// Context stores additional codec options
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// MaxMsgSize sets the max message size
|
||||
@@ -28,6 +34,13 @@ func MaxMsgSize(n int) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// TagName sets the codec tag name in struct
|
||||
func TagName(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.TagName = n
|
||||
}
|
||||
}
|
||||
|
||||
// Logger sets the logger
|
||||
func Logger(l logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
@@ -52,10 +65,12 @@ func Meter(m meter.Meter) Option {
|
||||
// NewOptions returns new options
|
||||
func NewOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Context: context.Background(),
|
||||
Logger: logger.DefaultLogger,
|
||||
Meter: meter.DefaultMeter,
|
||||
Tracer: tracer.DefaultTracer,
|
||||
MaxMsgSize: DefaultMaxMsgSize,
|
||||
TagName: DefaultTagName,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
|
||||
Reference in New Issue
Block a user