2016-12-13 17:19:04 +01:00
|
|
|
package user_endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-15 16:30:14 +01:00
|
|
|
|
2016-12-13 17:19:04 +01:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
|
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
|
|
|
context "golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Errorf
|
|
|
|
|
2016-12-25 19:55:34 +01:00
|
|
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
|
|
|
2016-12-13 17:19:04 +01:00
|
|
|
type Endpoints struct {
|
|
|
|
CreateUserEndpoint endpoint.Endpoint
|
|
|
|
|
|
|
|
GetUserEndpoint endpoint.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Endpoints) CreateUser(ctx context.Context, in *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
|
|
|
|
out, err := e.CreateUserEndpoint(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.CreateUserResponse{ErrMsg: err.Error()}, err
|
|
|
|
}
|
|
|
|
return out.(*pb.CreateUserResponse), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Endpoints) GetUser(ctx context.Context, in *pb.GetUserRequest) (*pb.GetUserResponse, error) {
|
|
|
|
out, err := e.GetUserEndpoint(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.GetUserResponse{ErrMsg: err.Error()}, err
|
|
|
|
}
|
|
|
|
return out.(*pb.GetUserResponse), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeCreateUserEndpoint(svc pb.UserServiceServer) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(*pb.CreateUserRequest)
|
|
|
|
rep, err := svc.CreateUser(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.CreateUserResponse{ErrMsg: err.Error()}, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeGetUserEndpoint(svc pb.UserServiceServer) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(*pb.GetUserRequest)
|
|
|
|
rep, err := svc.GetUser(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.GetUserResponse{ErrMsg: err.Error()}, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeEndpoints(svc pb.UserServiceServer) Endpoints {
|
|
|
|
return Endpoints{
|
|
|
|
|
|
|
|
CreateUserEndpoint: MakeCreateUserEndpoint(svc),
|
|
|
|
|
|
|
|
GetUserEndpoint: MakeGetUserEndpoint(svc),
|
|
|
|
}
|
|
|
|
}
|