register: add Codec option
All checks were successful
coverage / build (push) Successful in 1m3s
test / test (push) Successful in 3m31s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-12-27 19:33:46 +03:00
parent 470263ff5f
commit 277f04ba19

View File

@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"time" "time"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/meter" "go.unistack.org/micro/v3/meter"
"go.unistack.org/micro/v3/tracer" "go.unistack.org/micro/v3/tracer"
@ -26,6 +27,8 @@ type Options struct {
Name string Name string
// Addrs specifies register addrs // Addrs specifies register addrs
Addrs []string Addrs []string
// Codec used to marshal/unmarshal data in register
Codec codec.Codec
// Timeout specifies timeout // Timeout specifies timeout
Timeout time.Duration Timeout time.Duration
} }
@ -37,6 +40,7 @@ func NewOptions(opts ...Option) Options {
Meter: meter.DefaultMeter, Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer, Tracer: tracer.DefaultTracer,
Context: context.Background(), Context: context.Background(),
Codec: codec.NewCodec(),
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
@ -310,3 +314,11 @@ func Name(n string) Option {
o.Name = n o.Name = n
} }
} }
type codecKey struct{}
func Codec(c codec.Codec) Option {
return func(o *Options) {
o.Codec = c
}
}