break out ws.go

This commit is contained in:
Bel LaPointe
2024-12-14 20:37:17 -07:00
parent 0db285d4d4
commit 0b1900a7e0
3 changed files with 44 additions and 31 deletions

29
cmd/server/ws.go Normal file
View 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")
}