package proxy import ( "context" "gitee.com/timedb/wheatCache/gateway/codec" "gitee.com/timedb/wheatCache/pkg/logx" "gitee.com/timedb/wheatCache/pkg/proto" "google.golang.org/grpc" "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) { 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) } 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()))) return ctx, cli, err } }