diff --git a/.travis.yml b/.travis.yml index 58e4772f3ba..90785f004b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ install: script: - make realclean && make examples - test -z "$(git status --porcelain)" || (git status; git diff; exit 1) -- env GLOG_logtostderr=1 go test -v github.com/gengo/grpc-gateway/... +- env GLOG_logtostderr=1 go test -race -v github.com/gengo/grpc-gateway/... - golint github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/... - golint github.com/gengo/grpc-gateway/runtime/... - golint github.com/gengo/grpc-gateway/utilities/... diff --git a/Makefile b/Makefile index 3d6a6ec7b42..ce3d7199d6a 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ $(EXAMPLE_SWAGGERSRCS): $(SWAGGER_PLUGIN) $(SWAGGER_EXAMPLES) examples: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS) $(EXAMPLE_SWAGGERSRCS) test: examples - go test $(PKG)/... + go test -race $(PKG)/... clean distclean: rm -f $(GATEWAY_PLUGIN) diff --git a/examples/examplepb/a_bit_of_everything.pb.gw.go b/examples/examplepb/a_bit_of_everything.pb.gw.go index 963cdbcc234..ccc8d7ebd5b 100644 --- a/examples/examplepb/a_bit_of_everything.pb.gw.go +++ b/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -493,16 +493,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("POST", pattern_ABitOfEverythingService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Create_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -518,16 +516,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("POST", pattern_ABitOfEverythingService_CreateBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_CreateBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -543,16 +539,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("POST", pattern_ABitOfEverythingService_BulkCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_BulkCreate_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -568,16 +562,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("GET", pattern_ABitOfEverythingService_Lookup_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Lookup_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -593,16 +585,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("GET", pattern_ABitOfEverythingService_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_List_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -618,16 +608,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("PUT", pattern_ABitOfEverythingService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Update_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -643,16 +631,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("DELETE", pattern_ABitOfEverythingService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Delete_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -668,16 +654,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("GET", pattern_ABitOfEverythingService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -693,16 +677,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("POST", pattern_ABitOfEverythingService_Echo_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Echo_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -718,16 +700,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("GET", pattern_ABitOfEverythingService_Echo_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_Echo_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -743,16 +723,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se mux.Handle("POST", pattern_ABitOfEverythingService_BulkEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_ABitOfEverythingService_BulkEcho_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) diff --git a/examples/examplepb/echo_service.pb.gw.go b/examples/examplepb/echo_service.pb.gw.go index a9b765b1c1e..6ab992ad9f8 100644 --- a/examples/examplepb/echo_service.pb.gw.go +++ b/examples/examplepb/echo_service.pb.gw.go @@ -102,16 +102,14 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn mux.Handle("POST", pattern_EchoService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_EchoService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -127,16 +125,14 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn mux.Handle("POST", pattern_EchoService_EchoBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_EchoService_EchoBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) diff --git a/examples/examplepb/flow_combination.pb.gw.go b/examples/examplepb/flow_combination.pb.gw.go index 10d69f98830..6230e23a50d 100644 --- a/examples/examplepb/flow_combination.pb.gw.go +++ b/examples/examplepb/flow_combination.pb.gw.go @@ -1006,16 +1006,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1031,16 +1029,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1056,16 +1052,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_StreamEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_StreamEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1081,16 +1075,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_StreamEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_StreamEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1106,16 +1098,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1131,16 +1121,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1156,16 +1144,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1181,16 +1167,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1206,16 +1190,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1231,16 +1213,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1256,16 +1236,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyRpc_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1281,16 +1259,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathSingleNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1306,16 +1282,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1331,16 +1305,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1356,16 +1328,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1381,16 +1351,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1406,16 +1374,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1431,16 +1397,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1456,16 +1420,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1481,16 +1443,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1506,16 +1466,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1531,16 +1489,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcBodyStream_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1556,16 +1512,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathSingleNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1581,16 +1535,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1606,16 +1558,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) @@ -1631,16 +1581,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_FlowCombination_RpcPathNestedStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index 27ac672c6d0..37bbc64544b 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -271,16 +271,14 @@ func Register{{$svc.GetName}}Handler(ctx context.Context, mux *runtime.ServeMux, mux.Handle({{$b.HTTPMethod | printf "%q"}}, pattern_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(ctx) defer cancel() - closeNotifier, ok := w.(http.CloseNotifier) - if ok { - closeNotify := closeNotifier.CloseNotify() - go func() { + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { select { - case <-ctx.Done(): - case <-closeNotify: + case <-done: + case <-closed: cancel() } - }() + }(ctx.Done(), cn.CloseNotify()) } resp, md, err := request_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(runtime.AnnotateContext(ctx, req), client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md)