This commit is contained in:
Daniel 2024-08-04 07:39:52 -04:00
parent 43ec360d08
commit 95452e4e02
4 changed files with 4 additions and 14 deletions

View file

@ -107,19 +107,10 @@ func main() {
} }
}() }()
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for { for {
select { select {
case <-done: case <-done:
return return
case t := <-ticker.C:
err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))
if err != nil {
log.Println("write:", err)
return
}
case <-interrupt: case <-interrupt:
log.Println("interrupt") log.Println("interrupt")

View file

@ -2,7 +2,6 @@ package auth
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -103,7 +102,7 @@ func (a *authenticator) routeAuth(w http.ResponseWriter, r *http.Request) {
} }
username, password := r.PostFormValue("username"), r.PostFormValue("password") username, password := r.PostFormValue("username"), r.PostFormValue("password")
if username == "" || password == "" { if username == "" || password == "" {
http.Error(w, "blank credentials"+fmt.Sprint(r.Form), http.StatusBadRequest) http.Error(w, "blank credentials", http.StatusBadRequest)
return return
} }

View file

@ -87,7 +87,7 @@ func (conn *wsConn) readPump(reg Registry, c Client) {
_, message, err := conn.ReadMessage() _, message, err := conn.ReadMessage()
if err != nil { if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) { if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Error().Err(err).Msg("read failed") return
} }
break break
@ -153,6 +153,6 @@ func (conn *wsConn) writeMessage(w io.WriteCloser, msg *pb.Message) {
} }
} }
func (n *wsManager) InstallPrivateRoutes(r chi.Router) { func (n *wsManager) PrivateRoutes(r chi.Router) {
r.HandleFunc("/ws", n.serveWS) r.HandleFunc("/ws", n.serveWS)
} }

View file

@ -18,7 +18,7 @@ func (s *Server) setupRoutes() {
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
// authenticated routes // authenticated routes
r.Use(s.auth.VerifyMiddleware(), s.auth.AuthMiddleware()) r.Use(s.auth.VerifyMiddleware(), s.auth.AuthMiddleware())
s.nex.InstallPrivateRoutes(r) s.nex.PrivateRoutes(r)
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {