53 lines
1.3 KiB
Cheetah
53 lines
1.3 KiB
Cheetah
package {{.File.Package}}_endpoints
|
|
|
|
{{$file := .File}}
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
context "golang.org/x/net/context"
|
|
pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb"
|
|
"github.com/go-kit/kit/endpoint"
|
|
)
|
|
|
|
var _ = fmt.Errorf
|
|
|
|
type Endpoints struct {
|
|
{{range .Service.Method}}
|
|
{{.Name}}Endpoint endpoint.Endpoint
|
|
{{end}}
|
|
}
|
|
|
|
{{range .Service.Method}}
|
|
/*{{. | prettyjson}}*/
|
|
|
|
func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
|
out, err := e.{{.Name}}Endpoint(ctx, in)
|
|
if err != nil {
|
|
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
|
}
|
|
return out.(*pb.{{.OutputType | splitArray "." | last}}), err
|
|
}
|
|
{{end}}
|
|
|
|
{{range .Service.Method}}
|
|
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(*pb.{{.InputType | splitArray "." | last}})
|
|
rep, err := svc.{{.Name}}(ctx, req)
|
|
if err != nil {
|
|
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
|
}
|
|
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}}
|
|
}
|
|
}
|