2016-12-13 13:05:06 +03:00
|
|
|
package session_endpoints
|
2016-12-13 17:31:37 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-15 18:30:14 +03:00
|
|
|
|
2016-12-13 17:31:37 +03:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
2016-12-13 18:11:50 +03:00
|
|
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
2016-12-13 17:31:37 +03:00
|
|
|
context "golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Errorf
|
|
|
|
|
|
|
|
type Endpoints struct {
|
|
|
|
LoginEndpoint endpoint.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Endpoints) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
|
|
|
|
out, err := e.LoginEndpoint(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.LoginResponse{ErrMsg: err.Error()}, err
|
|
|
|
}
|
2016-12-13 18:03:16 +03:00
|
|
|
return out.(*pb.LoginResponse), err
|
2016-12-13 17:31:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(*pb.LoginRequest)
|
|
|
|
rep, err := svc.Login(ctx, req)
|
|
|
|
if err != nil {
|
2016-12-13 18:03:16 +03:00
|
|
|
return &pb.LoginResponse{ErrMsg: err.Error()}, err
|
2016-12-13 17:31:37 +03:00
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeEndpoints(svc pb.SessionServiceServer) Endpoints {
|
|
|
|
return Endpoints{
|
|
|
|
|
|
|
|
LoginEndpoint: MakeLoginEndpoint(svc),
|
|
|
|
}
|
|
|
|
}
|