56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package workflows
|
|
|
|
import (
|
|
"fmt"
|
|
"inp2025/middlewares"
|
|
"inp2025/tcp"
|
|
"io"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func pongHandler(w tcp.ResponseWriter, req *tcp.Request) error {
|
|
w.WriteHeader(tcp.StatusOK)
|
|
_, err := io.WriteString(w, string(req.Params["msg"]))
|
|
return err
|
|
}
|
|
|
|
func tickHandler(w tcp.ResponseWriter, req *tcp.Request) error {
|
|
zap.L().Info("Run tickHandler")
|
|
for {
|
|
w.SocketSendString(fmt.Sprintf("time: %s", time.Now().String()))
|
|
time.Sleep(time.Second)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func LobbyServer() *tcp.Router {
|
|
router := tcp.NewRouter().
|
|
Use(middlewares.ErrorHandler).
|
|
Use(middlewares.AccessLog)
|
|
|
|
// test
|
|
test := router.Group("/test").
|
|
Use(middlewares.NMSL)
|
|
test.SOCKET("/tick", tickHandler)
|
|
test.GET("/ping", pongHandler)
|
|
|
|
/*
|
|
auth := router.Group("/auth")
|
|
auth.POST("/register")
|
|
auth.POST("/login")
|
|
auth.POST("/logout")
|
|
|
|
api := router.Group("/api")
|
|
api.GET("/online-users")
|
|
api.GET("/rooms")
|
|
api.GET("/invitations")
|
|
api.GET("/current-invitation")
|
|
api.POST("/invite")
|
|
api.POST("/accept-invitition")
|
|
*/
|
|
|
|
return router
|
|
}
|