2016-12-25 21:55:34 +03:00
|
|
|
package session_clientgrpc
|
|
|
|
|
|
|
|
import (
|
2017-03-16 17:41:09 +03:00
|
|
|
context "context"
|
|
|
|
|
2016-12-25 21:55:34 +03: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"
|
|
|
|
|
2018-09-12 21:29:07 +03:00
|
|
|
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 21:55:34 +03: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
|
|
|
|
}
|