Better reliability on generated message names
This commit is contained in:
parent
d0ac6afb18
commit
88a2f47522
@ -19,22 +19,24 @@ type Endpoints struct {
|
||||
}
|
||||
|
||||
{{range .Service.Method}}
|
||||
func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) {
|
||||
/*{{. | 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.{{.Name}}Response{ErrMsg: err.Error()}, err
|
||||
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
||||
}
|
||||
return out.(*pb.{{.Name}}Response), 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.{{.Name}}Request)
|
||||
req := request.(*pb.{{.InputType | splitArray "." | last}})
|
||||
rep, err := svc.{{.Name}}(ctx, req)
|
||||
if err != nil {
|
||||
return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err
|
||||
return &pb.{{.OutputType | splitArray "." | last}}{ErrMsg: err.Error()}, err
|
||||
}
|
||||
return rep, nil
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ type grpcServer struct {
|
||||
}
|
||||
|
||||
{{range .Service.Method}}
|
||||
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) {
|
||||
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
|
||||
_, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rep.(*pb.{{.Name}}Response), nil
|
||||
return rep.(*pb.{{.OutputType | splitArray "." | last}}), nil
|
||||
}
|
||||
|
||||
func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
@ -53,7 +53,7 @@ func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface
|
||||
}
|
||||
|
||||
func encode{{.Name}}Response(ctx context.Context, response interface{}) (interface{}, error) {
|
||||
resp := response.(*pb.{{.Name}}Response)
|
||||
resp := response.(*pb.{{.OutputType | splitArray "." | last}})
|
||||
return resp, nil
|
||||
}
|
||||
{{end}}
|
||||
|
@ -26,7 +26,7 @@ func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}S
|
||||
}
|
||||
|
||||
func decode{{.Name}}Request(ctx context.Context, r *http.Request) (interface{}, error) {
|
||||
var req pb.{{.Name}}Request
|
||||
var req pb.{{.InputType | splitArray "." | last}}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user