protoc-gen-go-micro/examples/go-kit/services/user/gen/client/grpc/client.go
2017-03-16 16:15:34 +01:00

71 lines
1.9 KiB
Go

package user_clientgrpc
import (
context "context"
jwt "github.com/go-kit/kit/auth/jwt"
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/log"
grpctransport "github.com/go-kit/kit/transport/grpc"
"google.golang.org/grpc"
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
)
func New(conn *grpc.ClientConn, logger log.Logger) pb.UserServiceServer {
var createuserEndpoint endpoint.Endpoint
{
createuserEndpoint = grpctransport.NewClient(
conn,
"user.UserService",
"CreateUser",
EncodeCreateUserRequest,
DecodeCreateUserResponse,
pb.CreateUserResponse{},
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
).Endpoint()
}
var getuserEndpoint endpoint.Endpoint
{
getuserEndpoint = grpctransport.NewClient(
conn,
"user.UserService",
"GetUser",
EncodeGetUserRequest,
DecodeGetUserResponse,
pb.GetUserResponse{},
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
).Endpoint()
}
return &endpoints.Endpoints{
CreateUserEndpoint: createuserEndpoint,
GetUserEndpoint: getuserEndpoint,
}
}
func EncodeCreateUserRequest(_ context.Context, request interface{}) (interface{}, error) {
req := request.(*pb.CreateUserRequest)
return req, nil
}
func DecodeCreateUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
response := grpcResponse.(*pb.CreateUserResponse)
return response, nil
}
func EncodeGetUserRequest(_ context.Context, request interface{}) (interface{}, error) {
req := request.(*pb.GetUserRequest)
return req, nil
}
func DecodeGetUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
response := grpcResponse.(*pb.GetUserResponse)
return response, nil
}