[v3] remove using global map for default codecs (#224)
* remove using global map for default codecs * fix tests
This commit is contained in:
@@ -17,11 +17,6 @@ import (
|
|||||||
"go.unistack.org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultCodecs will be used to encode/decode data
|
|
||||||
var DefaultCodecs = map[string]codec.Codec{
|
|
||||||
"application/octet-stream": codec.NewCodec(),
|
|
||||||
}
|
|
||||||
|
|
||||||
type noopClient struct {
|
type noopClient struct {
|
||||||
funcPublish FuncPublish
|
funcPublish FuncPublish
|
||||||
funcBatchPublish FuncBatchPublish
|
funcBatchPublish FuncBatchPublish
|
||||||
@@ -178,9 +173,6 @@ func (n *noopClient) newCodec(contentType string) (codec.Codec, error) {
|
|||||||
if cf, ok := n.opts.Codecs[contentType]; ok {
|
if cf, ok := n.opts.Codecs[contentType]; ok {
|
||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
if cf, ok := DefaultCodecs[contentType]; ok {
|
|
||||||
return cf, nil
|
|
||||||
}
|
|
||||||
return nil, codec.ErrUnknownContentType
|
return nil, codec.ErrUnknownContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.unistack.org/micro/v3/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testHook struct {
|
type testHook struct {
|
||||||
@@ -19,7 +21,7 @@ func (t *testHook) Publish(fn FuncPublish) FuncPublish {
|
|||||||
func TestNoopHook(t *testing.T) {
|
func TestNoopHook(t *testing.T) {
|
||||||
h := &testHook{}
|
h := &testHook{}
|
||||||
|
|
||||||
c := NewClient(Hooks(HookPublish(h.Publish)))
|
c := NewClient(Codec("application/octet-stream", codec.NewCodec()), Hooks(HookPublish(h.Publish)))
|
||||||
|
|
||||||
if err := c.Init(); err != nil {
|
if err := c.Init(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ func NewOptions(opts ...Option) Options {
|
|||||||
options := Options{
|
options := Options{
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
ContentType: DefaultContentType,
|
ContentType: DefaultContentType,
|
||||||
Codecs: DefaultCodecs,
|
Codecs: make(map[string]codec.Codec),
|
||||||
CallOptions: CallOptions{
|
CallOptions: CallOptions{
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
Backoff: DefaultBackoff,
|
Backoff: DefaultBackoff,
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func TestTime(t *testing.T) {
|
|||||||
WithHandlerFunc(slog.NewTextHandler),
|
WithHandlerFunc(slog.NewTextHandler),
|
||||||
logger.WithAddStacktrace(true),
|
logger.WithAddStacktrace(true),
|
||||||
logger.WithTimeFunc(func() time.Time {
|
logger.WithTimeFunc(func() time.Time {
|
||||||
return time.Unix(0, 0)
|
return time.Unix(0, 0).UTC()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
if err := l.Init(logger.WithFields("key1", "val1")); err != nil {
|
if err := l.Init(logger.WithFields("key1", "val1")); err != nil {
|
||||||
@@ -71,8 +71,7 @@ func TestTime(t *testing.T) {
|
|||||||
|
|
||||||
l.Error(ctx, "msg1", errors.New("err"))
|
l.Error(ctx, "msg1", errors.New("err"))
|
||||||
|
|
||||||
if !bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T03:00:00.000000000+03:00`)) &&
|
if !bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T00:00:00.000000000Z`)) {
|
||||||
!bytes.Contains(buf.Bytes(), []byte(`timestamp=1970-01-01T00:00:00.000000000Z`)) {
|
|
||||||
t.Fatalf("logger error not works, buf contains: %s", buf.Bytes())
|
t.Fatalf("logger error not works, buf contains: %s", buf.Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,6 @@ import (
|
|||||||
"go.unistack.org/micro/v3/util/rand"
|
"go.unistack.org/micro/v3/util/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultCodecs will be used to encode/decode
|
|
||||||
var DefaultCodecs = map[string]codec.Codec{
|
|
||||||
"application/octet-stream": codec.NewCodec(),
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultContentType = "application/json"
|
defaultContentType = "application/json"
|
||||||
)
|
)
|
||||||
@@ -93,9 +88,6 @@ func (n *noopServer) newCodec(contentType string) (codec.Codec, error) {
|
|||||||
if cf, ok := n.opts.Codecs[contentType]; ok {
|
if cf, ok := n.opts.Codecs[contentType]; ok {
|
||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
if cf, ok := DefaultCodecs[contentType]; ok {
|
|
||||||
return cf, nil
|
|
||||||
}
|
|
||||||
return nil, codec.ErrUnknownContentType
|
return nil, codec.ErrUnknownContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user