grpc-gateway: wrap with wsproxy

This commit is contained in:
Adphi 2021-12-07 19:53:16 +01:00
parent 819b3c9ce6
commit eed8fd3501
3 changed files with 6 additions and 3 deletions

3
go.mod
View File

@ -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

1
go.sum
View File

@ -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=

View File

@ -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
}