2016-12-13 15:31:37 +01:00
|
|
|
package {{.File.Package}}_endpoints
|
|
|
|
|
|
|
|
{{$file := .File}}
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-15 16:28:04 +01:00
|
|
|
|
2016-12-13 15:31:37 +01:00
|
|
|
context "golang.org/x/net/context"
|
2016-12-15 16:28:04 +01:00
|
|
|
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
2016-12-13 15:31:37 +01:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Errorf
|
|
|
|
|
|
|
|
type Endpoints struct {
|
|
|
|
{{range .Service.Method}}
|
|
|
|
{{.Name}}Endpoint endpoint.Endpoint
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
2016-12-21 10:32:27 +01:00
|
|
|
/*{{. | prettyjson}}*/
|
|
|
|
|
|
|
|
func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
2016-12-13 15:31:37 +01:00
|
|
|
out, err := e.{{.Name}}Endpoint(ctx, in)
|
|
|
|
if err != nil {
|
2016-12-21 10:32:27 +01:00
|
|
|
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
2016-12-13 15:31:37 +01:00
|
|
|
}
|
2016-12-21 10:32:27 +01:00
|
|
|
return out.(*pb.{{.OutputType | splitArray "." | last}}), err
|
2016-12-13 15:31:37 +01:00
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
|
|
|
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint {
|
2016-12-15 16:28:04 +01:00
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
2016-12-21 10:32:27 +01:00
|
|
|
req := request.(*pb.{{.InputType | splitArray "." | last}})
|
2016-12-13 15:31:37 +01:00
|
|
|
rep, err := svc.{{.Name}}(ctx, req)
|
|
|
|
if err != nil {
|
2016-12-21 10:32:27 +01:00
|
|
|
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
2016-12-13 15:31:37 +01: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}}
|
|
|
|
}
|
|
|
|
}
|