47 lines
1.1 KiB
Go
Raw Normal View History

2016-12-13 11:05:06 +01:00
package session_endpoints
2016-12-13 15:31:37 +01:00
import (
2017-03-16 15:41:09 +01:00
context "context"
2016-12-13 15:31:37 +01:00
"fmt"
2016-12-13 15:31:37 +01:00
"github.com/go-kit/kit/endpoint"
pb "moul.io/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
2017-03-16 15:41:09 +01:00
oldcontext "golang.org/x/net/context"
2016-12-13 15:31:37 +01:00
)
2017-03-16 15:41:09 +01:00
var _ = endpoint.Chain
2016-12-13 15:31:37 +01:00
var _ = fmt.Errorf
2017-03-16 15:41:09 +01:00
var _ = context.Background
2016-12-13 15:31:37 +01:00
2016-12-25 19:55:34 +01:00
type StreamEndpoint func(server interface{}, req interface{}) (err error)
2016-12-13 15:31:37 +01:00
type Endpoints struct {
LoginEndpoint endpoint.Endpoint
}
2017-03-16 15:41:09 +01:00
func (e *Endpoints) Login(ctx oldcontext.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
2016-12-13 15:31:37 +01:00
out, err := e.LoginEndpoint(ctx, in)
if err != nil {
return &pb.LoginResponse{ErrMsg: err.Error()}, err
}
2016-12-13 16:03:16 +01:00
return out.(*pb.LoginResponse), err
2016-12-13 15:31:37 +01: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 16:03:16 +01:00
return &pb.LoginResponse{ErrMsg: err.Error()}, err
2016-12-13 15:31:37 +01:00
}
return rep, nil
}
}
func MakeEndpoints(svc pb.SessionServiceServer) Endpoints {
return Endpoints{
LoginEndpoint: MakeLoginEndpoint(svc),
}
}