Enha: sqlx instead of pgx

This commit is contained in:
Grail Finder
2025-07-01 16:00:17 +03:00
parent 70f83f1002
commit e989590e74
18 changed files with 631 additions and 72 deletions

View File

@ -5,6 +5,7 @@ import (
"gralias/config"
"gralias/models"
"gralias/pkg/cache"
"gralias/repos"
"html/template"
"log/slog"
"net/http"
@ -17,6 +18,7 @@ var (
cfg *config.Config
memcache cache.Cache
Notifier *broker.Broker
repo repos.AllRepos
)
func init() {
@ -30,6 +32,7 @@ func init() {
cache.MemCache.StartBackupRoutine(15 * time.Second) // Reduced backup interval
// bot loader
// check the rooms if it has bot_{digits} in them, create bots if have
repo = repos.NewRepoProvider("sqlite3://../gralias.db")
recoverBots()
// if player has a roomID, but no team and role, try to recover
recoverPlayers()
@ -57,7 +60,11 @@ func HandleHome(w http.ResponseWriter, r *http.Request) {
}
}
if fi != nil && fi.Room == nil {
fi.List = listRooms(false)
rooms, err := repo.ListRooms(r.Context())
if err != nil {
log.Error("failed to list rooms;", "error", err)
}
fi.List = rooms
}
if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil {
log.Error("failed to exec templ;", "error", err, "templ", "base")