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}}
|
2016-12-21 12:32:27 +03:00
|
|
|
/*{{. | prettyjson}}*/
|
|
|
|
|
|
|
|
func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
2016-12-13 17:31:37 +03:00
|
|
|
out, err := e.{{.Name}}Endpoint(ctx, in)
|
|
|
|
if err != nil {
|
2016-12-21 12:32:27 +03:00
|
|
|
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
2016-12-13 17:31:37 +03:00
|
|
|
}
|
2016-12-21 12:32:27 +03:00
|
|
|
return out.(*pb.{{.OutputType | splitArray "." | last}}), 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-21 12:32:27 +03:00
|
|
|
req := request.(*pb.{{.InputType | splitArray "." | last}})
|
2016-12-13 17:31:37 +03:00
|
|
|
rep, err := svc.{{.Name}}(ctx, req)
|
|
|
|
if err != nil {
|
2016-12-21 12:32:27 +03:00
|
|
|
return &pb.{{.OutputType | splitArray "." | last}}{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}}
|
|
|
|
}
|
|
|
|
}
|