fixed metadata hooks
Some checks failed
lint / lint (pull_request) Successful in 2m27s
test / test (pull_request) Successful in 3m5s
coverage / build (pull_request) Failing after 6m31s

This commit is contained in:
2025-04-23 20:50:44 +03:00
parent 70f0ace92e
commit 6c9dbc77dd

View File

@@ -5,13 +5,13 @@ import (
"go.unistack.org/micro/v4/client" "go.unistack.org/micro/v4/client"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v4/metadata"
"go.unistack.org/micro/v4/options"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v4/server"
) )
type wrapper struct { type wrapper struct {
client.Client
keys []string keys []string
client.Client
} }
func NewClientWrapper(keys ...string) client.Wrapper { func NewClientWrapper(keys ...string) client.Wrapper {
@@ -36,8 +36,8 @@ func NewClientCallWrapper(keys ...string) client.CallWrapper {
omd = metadata.New(len(imd)) omd = metadata.New(len(imd))
} }
for _, k := range keys { for _, k := range keys {
if v, ok := imd.Get(k); ok && v != "" { if v, ok := imd.Get(k); ok {
omd.Set(k, v) omd.Add(k, v...)
} }
} }
if !ook { if !ook {
@@ -49,7 +49,7 @@ func NewClientCallWrapper(keys ...string) client.CallWrapper {
} }
} }
func (w *wrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...options.Option) error { func (w *wrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
if w.keys == nil { if w.keys == nil {
return w.Client.Call(ctx, req, rsp, opts...) return w.Client.Call(ctx, req, rsp, opts...)
} }
@@ -59,8 +59,8 @@ func (w *wrapper) Call(ctx context.Context, req client.Request, rsp interface{},
omd = metadata.New(len(imd)) omd = metadata.New(len(imd))
} }
for _, k := range w.keys { for _, k := range w.keys {
if v, ok := imd.Get(k); ok && v != "" { if v, ok := imd.Get(k); ok {
omd.Set(k, v) omd.Add(k, v...)
} }
} }
if !ook { if !ook {
@@ -70,7 +70,7 @@ func (w *wrapper) Call(ctx context.Context, req client.Request, rsp interface{},
return w.Client.Call(ctx, req, rsp, opts...) return w.Client.Call(ctx, req, rsp, opts...)
} }
func (w *wrapper) Stream(ctx context.Context, req client.Request, opts ...options.Option) (client.Stream, error) { func (w *wrapper) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
if w.keys == nil { if w.keys == nil {
return w.Client.Stream(ctx, req, opts...) return w.Client.Stream(ctx, req, opts...)
} }
@@ -80,8 +80,8 @@ func (w *wrapper) Stream(ctx context.Context, req client.Request, opts ...option
omd = metadata.New(len(imd)) omd = metadata.New(len(imd))
} }
for _, k := range w.keys { for _, k := range w.keys {
if v, ok := imd.Get(k); ok && v != "" { if v, ok := imd.Get(k); ok {
omd.Set(k, v) omd.Add(k, v...)
} }
} }
if !ook { if !ook {
@@ -103,8 +103,8 @@ func NewServerHandlerWrapper(keys ...string) server.HandlerWrapper {
omd = metadata.New(len(imd)) omd = metadata.New(len(imd))
} }
for _, k := range keys { for _, k := range keys {
if v, ok := imd.Get(k); ok && v != "" { if v, ok := imd.Get(k); ok {
omd.Set(k, v) omd.Add(k, v...)
} }
} }
if !ook { if !ook {