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"
|
|
|
|
)
|
|
|
|
|
2016-12-26 18:20:46 +03:00
|
|
|
var _ = endpoint.Chain
|
2016-12-13 17:31:37 +03:00
|
|
|
var _ = fmt.Errorf
|
2016-12-26 18:20:46 +03:00
|
|
|
var _ = context.Background
|
2016-12-13 17:31:37 +03:00
|
|
|
|
2016-12-23 21:20:44 +03:00
|
|
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
|
|
|
|
2016-12-13 17:31:37 +03:00
|
|
|
type Endpoints struct {
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 21:20:44 +03:00
|
|
|
{{if or (.ClientStreaming) (.ServerStreaming)}}
|
|
|
|
{{.Name}}Endpoint StreamEndpoint
|
|
|
|
{{else}}
|
|
|
|
{{.Name}}Endpoint endpoint.Endpoint
|
|
|
|
{{end}}
|
2016-12-13 17:31:37 +03:00
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 21:20:44 +03: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}}
|
|
|
|
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}}
|
|
|
|
{{end}}
|
2016-12-13 17:31:37 +03:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 21:20:44 +03: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 17:31:37 +03:00
|
|
|
}
|
2016-12-23 21:20:44 +03: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 17:31:37 +03:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
func MakeEndpoints(svc pb.{{.File.Package | title}}ServiceServer) Endpoints {
|
|
|
|
return Endpoints{
|
|
|
|
{{range .Service.Method}}
|
2016-12-23 21:20:44 +03:00
|
|
|
{{.Name}}Endpoint: Make{{.Name}}Endpoint(svc),
|
2016-12-13 17:31:37 +03:00
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|