Draft: big refactor

This commit is contained in:
2025-09-16 16:03:27 +08:00
parent f527230f1e
commit 85fa3dfe73
47 changed files with 1166 additions and 351 deletions

47
workflows/wordleServer.go Normal file
View File

@@ -0,0 +1,47 @@
package workflows
import (
"context"
"net/http"
"gitea.konchin.com/ytshih/inp2025/game/implements"
"gitea.konchin.com/ytshih/inp2025/game/server/middlewares"
"gitea.konchin.com/ytshih/inp2025/game/server/wordle"
"gitea.konchin.com/ytshih/inp2025/game/tracing"
"github.com/uptrace/bunrouter"
"go.uber.org/zap"
)
type ShutdownFunc = func()
func WordleServer(addr string) ShutdownFunc {
handlers := wordle.NewHandlers()
middlewareHandlers := middlewares.NewHandlers(
implements.NewBunDatabase(nil))
router := bunrouter.New()
apiGroup := router.NewGroup("/api").
Use(middlewareHandlers.ErrorHandler)
apiGroup.GET("/state",
handlers.WSGetState)
apiGroup.POST("/guess",
handlers.WSPostGuess)
server := &http.Server{
Addr: addr,
Handler: http.Handler(router),
}
go func() {
if err := server.ListenAndServe(); err != http.ErrServerClosed {
tracing.Logger.Error("wordle server failed", zap.Error(err))
}
}()
return func() {
if err := server.Shutdown(context.Background()); err != nil {
tracing.Logger.Error("failed to shutdown wordle server", zap.Error(err))
}
}
}