Add entrypoint
This commit is contained in:
@@ -23,7 +23,7 @@ func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb.
|
||||
if err != nil {
|
||||
return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err
|
||||
}
|
||||
return out.(*pb.{{.Name}}Reply), err
|
||||
return out.(*pb.{{.Name}}Response), err
|
||||
}
|
||||
{{end}}
|
||||
|
||||
@@ -33,7 +33,7 @@ func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoi
|
||||
req := request.(*pb.{{.Name}}Request)
|
||||
rep, err := svc.{{.Name}}(ctx, req)
|
||||
if err != nil {
|
||||
return &pb.{{.Name}}Reply{ErrMsg: err.Error()}, err
|
||||
return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err
|
||||
}
|
||||
return rep, nil
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package {{.File.Package}}_transportgrpc
|
||||
package {{.File.Package}}_grpctransport
|
||||
|
||||
{{$file := .File}}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
context "golang.org/x/net/context"
|
||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}"
|
||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||
endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints"
|
||||
endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints"
|
||||
)
|
||||
|
||||
// avoid import errors
|
||||
@@ -25,7 +25,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.{{.Fil
|
||||
endpoints.{{.Name}}Endpoint,
|
||||
decode{{.Name}}Request,
|
||||
encode{{.Name}}Response,
|
||||
options,
|
||||
options...,
|
||||
),
|
||||
{{end}}
|
||||
{{end}}
|
||||
@@ -40,12 +40,12 @@ type grpcServer struct {
|
||||
}
|
||||
|
||||
{{range .Service.Method}}
|
||||
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Reply, error) {
|
||||
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) {
|
||||
_, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rep.(*pb.{{.Name}}Reply), nil
|
||||
return rep.(*pb.{{.Name}}Response), 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}}Reply)
|
||||
resp := response.(*pb.{{.Name}}Response)
|
||||
return resp, nil
|
||||
}
|
||||
{{end}}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package {{.File.Package}}_transporthttp
|
||||
package {{.File.Package}}_httptransport
|
||||
|
||||
{{$file := .File}}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}"
|
||||
gokit_endpoint "github.com/go-kit/kit/endpoint"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints"
|
||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints"
|
||||
)
|
||||
|
||||
{{range .Service.Method}}
|
||||
@@ -21,7 +21,7 @@ func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}S
|
||||
endpoint,
|
||||
decode{{.Name}}Request,
|
||||
encode{{.Name}}Response,
|
||||
append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))...,
|
||||
[]httptransport.ServerOption{}...,
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user