forked from p93542168/wheat-cache
feat(gateway): add gateway refault
This commit is contained in:
parent
5fe201ca32
commit
57e84b6dee
|
@ -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...)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())))
|
||||
|
|
|
@ -5,5 +5,5 @@ type GetKeyBaseInterface interface {
|
|||
}
|
||||
|
||||
const (
|
||||
BaseKeyMethodKey = "BaseKey"
|
||||
BaseKeyMethodKey = "basekey"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue