From eed8fd3501c4759dee7e1c02b84c85cbd152fab6 Mon Sep 17 00:00:00 2001 From: Adphi Date: Tue, 7 Dec 2021 19:53:16 +0100 Subject: [PATCH] grpc-gateway: wrap with wsproxy --- go.mod | 3 ++- go.sum | 1 + service/gateway.go | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b013f6f..2e00eff 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/alta/protopatch v0.3.4 github.com/envoyproxy/protoc-gen-validate v0.6.0 - github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/fsnotify/fsnotify v1.4.9 github.com/fullstorydev/grpchan v1.0.2-0.20201120232431-d0ab778aeebd github.com/golang/protobuf v1.5.2 github.com/google/uuid v1.1.2 @@ -30,6 +30,7 @@ require ( github.com/spf13/cobra v1.1.3 github.com/spf13/viper v1.7.0 github.com/stretchr/testify v1.7.0 + github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 go.linka.cloud/protoc-gen-defaults v0.1.0 go.linka.cloud/protoc-gen-go-fields v0.1.1 go.linka.cloud/protofilters v0.2.2 diff --git a/go.sum b/go.sum index 476a745..369e4e8 100644 --- a/go.sum +++ b/go.sum @@ -675,6 +675,7 @@ github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eN github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= diff --git a/service/gateway.go b/service/gateway.go index 68dea35..b6c1fcc 100644 --- a/service/gateway.go +++ b/service/gateway.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/tmc/grpc-websocket-proxy/wsproxy" ) var defaultGatewayOptions = []runtime.ServeMuxOption{ @@ -21,9 +22,9 @@ func (s *service) gateway(opts ...runtime.ServeMuxOption) error { return err } if s.opts.gatewayPrefix != "" { - s.opts.mux.Handle(s.opts.gatewayPrefix+"/", http.StripPrefix(s.opts.gatewayPrefix, mux)) + s.opts.mux.Handle(s.opts.gatewayPrefix+"/", http.StripPrefix(s.opts.gatewayPrefix, wsproxy.WebsocketProxy(mux))) } else { - s.opts.mux.Handle("/", mux) + s.opts.mux.Handle("/", wsproxy.WebsocketProxy(mux)) } return nil }