move hooks #398

Merged
vtolstov merged 2 commits from devstigneev/micro:move_hooks_v4 into v4 2025-04-27 14:04:33 +03:00
5 changed files with 460 additions and 0 deletions
Showing only changes of commit 6c9dbc77dd - Show all commits

View File

@@ -5,13 +5,13 @@ import (
"go.unistack.org/micro/v4/client"
"go.unistack.org/micro/v4/metadata"
"go.unistack.org/micro/v4/options"
"go.unistack.org/micro/v4/server"
)
type wrapper struct {
client.Client
keys []string
client.Client
}
func NewClientWrapper(keys ...string) client.Wrapper {
@@ -36,8 +36,8 @@ func NewClientCallWrapper(keys ...string) client.CallWrapper {
omd = metadata.New(len(imd))
}
for _, k := range keys {
if v, ok := imd.Get(k); ok && v != "" {
omd.Set(k, v)
if v, ok := imd.Get(k); ok {
omd.Add(k, v...)
}
}
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 {
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))
}
for _, k := range w.keys {
if v, ok := imd.Get(k); ok && v != "" {
omd.Set(k, v)
if v, ok := imd.Get(k); ok {
omd.Add(k, v...)
}
}
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...)
}
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 {
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))
}
for _, k := range w.keys {
if v, ok := imd.Get(k); ok && v != "" {
omd.Set(k, v)
if v, ok := imd.Get(k); ok {
omd.Add(k, v...)
}
}
if !ook {
@@ -103,8 +103,8 @@ func NewServerHandlerWrapper(keys ...string) server.HandlerWrapper {
omd = metadata.New(len(imd))
}
for _, k := range keys {
if v, ok := imd.Get(k); ok && v != "" {
omd.Set(k, v)
if v, ok := imd.Get(k); ok {
omd.Add(k, v...)
}
}
if !ook {