break out ws.go
This commit is contained in:
29
cmd/server/ws.go
Normal file
29
cmd/server/ws.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
)
|
||||
|
||||
func isWS(r *http.Request) bool {
|
||||
return r.URL.Path == "/ws" || strings.HasPrefix(r.URL.Path, "/ws/")
|
||||
}
|
||||
|
||||
func (s *S) serveWS(httpw http.ResponseWriter, httpr *http.Request) error {
|
||||
ctx := httpr.Context()
|
||||
|
||||
c, err := websocket.Accept(httpw, httpr, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.CloseNow()
|
||||
|
||||
if err := c.Write(ctx, 1, []byte("hello world")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("not impl")
|
||||
}
|
||||
Reference in New Issue
Block a user