diff --git a/demo/server/main.go b/demo/server/main.go index 9dab937..0089555 100644 --- a/demo/server/main.go +++ b/demo/server/main.go @@ -32,7 +32,7 @@ func main() { //Setup HTTP / Websocket server router := http.NewServeMux() wsl := wasmws.NewWebSocketListener(appCtx) - router.HandleFunc("/grpc-proxy", wsl.HTTPAccept) + router.HandleFunc("/grpc-proxy", wsl.ServeHTTP) router.Handle("/", http.FileServer(http.Dir("./static"))) httpServer := &http.Server{Addr: ":8080", Handler: router} //Run HTTP server diff --git a/wslistener.go b/wslistener.go index d0562f5..a925fd1 100644 --- a/wslistener.go +++ b/wslistener.go @@ -21,7 +21,10 @@ type WebSockListener struct { acceptCh chan net.Conn } -var _ net.Listener = (*WebSockListener)(nil) +var ( + _ net.Listener = (*WebSockListener)(nil) + _ http.Handler = (*WebSockListener)(nil) +) //NewWebSocketListener constructs a new WebSockListener, the provided context //is for the lifetime of the listener. @@ -47,9 +50,9 @@ func NewWebSocketListener(ctx context.Context) *WebSockListener { return wsl } -//HTTPAccept is a method that is mean to be used as http.HandlerFunc to accept inbound HTTP requests +//ServeHTTP is a method that is mean to be used as http.HandlerFunc to accept inbound HTTP requests // that are websocket connections -func (wsl *WebSockListener) HTTPAccept(wtr http.ResponseWriter, req *http.Request) { +func (wsl *WebSockListener) ServeHTTP(wtr http.ResponseWriter, req *http.Request) { select { case <-wsl.ctx.Done(): http.Error(wtr, "503: Service is shutdown", http.StatusServiceUnavailable)