46 lines
1.2 KiB
Go
Raw Permalink Normal View History

2016-12-25 19:55:34 +01:00
package session_clientgrpc
import (
2017-03-16 15:41:09 +01:00
context "context"
2016-12-25 19:55:34 +01:00
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 "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
2016-12-25 19:55:34 +01:00
)
func New(conn *grpc.ClientConn, logger log.Logger) pb.SessionServiceServer {
var loginEndpoint endpoint.Endpoint
{
loginEndpoint = grpctransport.NewClient(
conn,
"session.SessionService",
"Login",
EncodeLoginRequest,
DecodeLoginResponse,
pb.LoginResponse{},
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
).Endpoint()
}
return &endpoints.Endpoints{
LoginEndpoint: loginEndpoint,
}
}
func EncodeLoginRequest(_ context.Context, request interface{}) (interface{}, error) {
req := request.(*pb.LoginRequest)
return req, nil
}
func DecodeLoginResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
response := grpcResponse.(*pb.LoginResponse)
return response, nil
}