2016-12-13 17:31:37 +03:00
|
|
|
package {{.File.Package}}_endpoints
|
|
|
|
|
|
|
|
{{$file := .File}}
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-15 18:28:04 +03:00
|
|
|
|
2016-12-13 17:31:37 +03:00
|
|
|
context "golang.org/x/net/context"
|
2016-12-15 18:28:04 +03:00
|
|
|
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
2016-12-13 17:31:37 +03:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Errorf
|
|
|
|
|
|
|
|
type Endpoints struct {
|
|
|
|
{{range .Service.Method}}
|
|
|
|
{{.Name}}Endpoint endpoint.Endpoint
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
|
|
|
func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) {
|
|
|
|
out, err := e.{{.Name}}Endpoint(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err
|
|
|
|
}
|
2016-12-13 18:03:16 +03:00
|
|
|
return out.(*pb.{{.Name}}Response), err
|
2016-12-13 17:31:37 +03:00
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
|
|
|
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint {
|
2016-12-15 18:28:04 +03:00
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
2016-12-13 17:31:37 +03:00
|
|
|
req := request.(*pb.{{.Name}}Request)
|
|
|
|
rep, err := svc.{{.Name}}(ctx, req)
|
|
|
|
if err != nil {
|
2016-12-13 18:03:16 +03:00
|
|
|
return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err
|
2016-12-13 17:31:37 +03:00
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
func MakeEndpoints(svc pb.{{.File.Package | title}}ServiceServer) Endpoints {
|
|
|
|
return Endpoints{
|
|
|
|
{{range .Service.Method}}
|
|
|
|
{{.Name}}Endpoint: Make{{.Name}}Endpoint(svc),
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|