diff --git a/client/middle/middle.go b/client/middle/middle.go index f5a1915..69f3ba4 100644 --- a/client/middle/middle.go +++ b/client/middle/middle.go @@ -18,10 +18,19 @@ func WithUnaryColonyClient(ctx context.Context, method string, req, reply interf if header == nil { return nil } + // meta 解析会出现 全部小写问题 header[proto.BaseKeyMethodKey] = key.GetKey().Key return nil } +func getKeyByKeyMapvalue(m map[string]string) []string { + l := make([]string, 0) + for key, value := range m { + l = append(l, key, value) + } + return l +} + func GetUnaryInterceptor(middleOpts ...ClientMiddle) grpc.UnaryClientInterceptor { return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { @@ -34,10 +43,11 @@ func GetUnaryInterceptor(middleOpts ...ClientMiddle) grpc.UnaryClientInterceptor } } - for key, value := range header { - ctx = metadata.AppendToOutgoingContext(ctx, key, value) - } + lm := getKeyByKeyMapvalue(header) - return invoker(ctx, method, req, reply, cc, opts...) + headerData := metadata.Pairs(lm...) + ctxH := metadata.NewOutgoingContext(ctx, headerData) + + return invoker(ctxH, method, req, reply, cc, opts...) } } diff --git a/gateway/proxy/director.go b/gateway/proxy/director.go index 19d546b..d610c13 100644 --- a/gateway/proxy/director.go +++ b/gateway/proxy/director.go @@ -26,7 +26,7 @@ func GetDirectorByServiceHash() StreamDirector { "grpc header is not found %s, please check the client interceptor", proto.BaseKeyMethodKey) } - logx.Infoln(baseKey) + logx.Infoln(baseKey[0]) // TODO hash, mock 直接转发到 storage dev 上 cli, err := grpc.DialContext(ctx, "127.0.0.1:5890", grpc.WithInsecure(), grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.Codec()))) diff --git a/pkg/proto/define.go b/pkg/proto/define.go index a82e599..e333d8b 100644 --- a/pkg/proto/define.go +++ b/pkg/proto/define.go @@ -5,5 +5,5 @@ type GetKeyBaseInterface interface { } const ( - BaseKeyMethodKey = "BaseKey" + BaseKeyMethodKey = "basekey" )