Skip to content

Commit

Permalink
Add Handler method to pass in client
Browse files Browse the repository at this point in the history
Right now if you want to embed the JSON proxy into your service you end
up having to have a client talking to loopback which is messy. With this
API addition you can simply pass in something which implements the
client interface -- meaning you could wrap it yourself and return
directly (without all the loopback and serialization overhead).
  • Loading branch information
jacksontj committed Sep 14, 2017
1 parent 8bec008 commit cdc117b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,12 @@ func Register{{$svc.GetName}}HandlerFromEndpoint(ctx context.Context, mux *runti
// Register{{$svc.GetName}}Handler registers the http handlers for service {{$svc.GetName}} to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func Register{{$svc.GetName}}Handler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
client := New{{$svc.GetName}}Client(conn)
return Register{{$svc.GetName}}HandlerClient(ctx, mux, New{{$svc.GetName}}Client(conn))
}
// Register{{$svc.GetName}}Handler registers the http handlers for service {{$svc.GetName}} to "mux".
// The handlers forward requests to the grpc endpoint over "client".
func Register{{$svc.GetName}}HandlerClient(ctx context.Context, mux *runtime.ServeMux, client {{$svc.GetName}}Client) error {
{{range $m := $svc.Methods}}
{{range $b := $m.Bindings}}
mux.Handle({{$b.HTTPMethod | printf "%q"}}, pattern_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
Expand Down

0 comments on commit cdc117b

Please sign in to comment.