2016-12-13 15:31:37 +01:00
|
|
|
package {{.File.Package}}_endpoints
|
|
|
|
|
|
|
|
{{$file := .File}}
|
|
|
|
|
|
|
|
import (
|
2017-03-16 15:41:09 +01:00
|
|
|
context "context"
|
2016-12-13 15:31:37 +01:00
|
|
|
"fmt"
|
2016-12-15 16:28:04 +01:00
|
|
|
|
2017-03-16 15:41:09 +01:00
|
|
|
oldcontext "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"
|
|
|
|
)
|
|
|
|
|
2016-12-26 16:20:46 +01:00
|
|
|
var _ = endpoint.Chain
|
2016-12-13 15:31:37 +01:00
|
|
|
var _ = fmt.Errorf
|
2016-12-26 16:20:46 +01:00
|
|
|
var _ = context.Background
|
2016-12-13 15:31:37 +01:00
|
|
|
|
2016-12-23 19:20:44 +01:00
|
|
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
|
|
|
2016-12-13 15:31:37 +01:00
|
|
|
type Endpoints struct {
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 19:20:44 +01:00
|
|
|
{{if or (.ClientStreaming) (.ServerStreaming)}}
|
|
|
|
{{.Name}}Endpoint StreamEndpoint
|
|
|
|
{{else}}
|
|
|
|
{{.Name}}Endpoint endpoint.Endpoint
|
|
|
|
{{end}}
|
2016-12-13 15:31:37 +01:00
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 19:20:44 +01:00
|
|
|
{{if .ServerStreaming}}
|
|
|
|
{{if .ClientStreaming}}
|
|
|
|
func (e *Endpoints){{.Name}}(server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
{{else}}
|
|
|
|
func (e *Endpoints){{.Name}}(in *pb.{{.Name}}Request, server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
{{else}}
|
|
|
|
{{if .ClientStreaming}}
|
|
|
|
func (e *Endpoints){{.Name}}(server pb.{{$file.Package | title}}Service_{{.Name}}Server) error {
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
{{else}}
|
2017-03-16 15:41:09 +01:00
|
|
|
func (e *Endpoints){{.Name}}(ctx oldcontext.Context, in *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
2016-12-23 19:20:44 +01:00
|
|
|
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}}
|
|
|
|
{{end}}
|
2016-12-13 15:31:37 +01:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 19:20:44 +01:00
|
|
|
{{if or (.ServerStreaming) (.ClientStreaming)}}
|
|
|
|
func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) StreamEndpoint {
|
|
|
|
return func(server interface{}, request interface{}) error {
|
|
|
|
{{if .ClientStreaming}}
|
|
|
|
return svc.{{.Name}}(server.(pb.{{$file.Package | title}}Service_{{.Name}}Server))
|
|
|
|
{{else}}
|
|
|
|
return svc.{{.Name}}(request.(*pb.{{.Name}}Request), server.(pb.{{$file.Package | title}}Service_{{.Name}}Server))
|
|
|
|
{{end}}
|
|
|
|
}
|
2016-12-13 15:31:37 +01:00
|
|
|
}
|
2016-12-23 19:20:44 +01:00
|
|
|
{{else}}
|
|
|
|
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}}
|
2016-12-13 15:31:37 +01:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
func MakeEndpoints(svc pb.{{.File.Package | title}}ServiceServer) Endpoints {
|
|
|
|
return Endpoints{
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 19:20:44 +01:00
|
|
|
{{.Name}}Endpoint: Make{{.Name}}Endpoint(svc),
|
2016-12-13 15:31:37 +01:00
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|