wheat-cache/gateway/proxy/director.go

36 lines
1.0 KiB
Go
Raw Normal View History

package proxy
import (
"context"
"gitee.com/timedb/wheatCache/gateway/codec"
2021-10-17 10:49:14 +08:00
"gitee.com/timedb/wheatCache/pkg/logx"
"gitee.com/timedb/wheatCache/pkg/proto"
"google.golang.org/grpc"
2021-10-17 10:49:14 +08:00
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
func GetDirectorByServiceHash() StreamDirector {
return func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {
2021-10-17 10:49:14 +08:00
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, nil, status.Errorf(codes.Unknown, "from FromIncomingContext err")
}
baseKey, ok := md[proto.BaseKeyMethodKey]
if !ok {
return nil, nil, status.Errorf(codes.Unknown,
"grpc header is not found %s, please check the client interceptor", proto.BaseKeyMethodKey)
}
2021-10-17 19:27:00 +08:00
logx.Infoln(baseKey[0])
2021-10-17 10:49:14 +08:00
// TODO hash, mock 直接转发到 storage dev 上
2021-10-16 22:53:11 +08:00
cli, err := grpc.DialContext(ctx, "127.0.0.1:5890", grpc.WithInsecure(), grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.Codec())))
return ctx, cli, err
}
}