aboutsummaryrefslogtreecommitdiff
path: root/backend/router.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-22 18:34:02 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-22 18:34:02 +0100
commitcbd5c09c5e1403709d4aabf91051443f147689e5 (patch)
tree5add0c1a15df56ec121a77f3d4bd895c7d5f19df /backend/router.go
parent9bba6dcbb2e83fe53604d38b89fb79ce47eacddd (diff)
refactor(backend): move db related in new package
Diffstat (limited to 'backend/router.go')
-rw-r--r--backend/router.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/backend/router.go b/backend/router.go
index f2ed775..161433d 100644
--- a/backend/router.go
+++ b/backend/router.go
@@ -14,6 +14,7 @@ import (
"strings"
"time"
+ "git.anhgelus.world/anhgelus/small-web/backend/storage"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog/v3"
@@ -24,7 +25,6 @@ const (
configKey = "config"
assetsFSKey = "assets_fs"
debugKey = "debug"
- dbKey = "db"
loginKey = "login"
)
@@ -95,7 +95,7 @@ func NewRouter(debug bool, cfg *Config, db *sql.DB, assets fs.FS) *chi.Mux {
ctx = context.WithValue(ctx, configKey, cfg)
ctx = context.WithValue(ctx, assetsFSKey, assets)
ctx = context.WithValue(ctx, debugKey, debug)
- return context.WithValue(ctx, dbKey, db)
+ return context.WithValue(ctx, storage.DBKey, db)
}
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -108,7 +108,7 @@ func NewRouter(debug bool, cfg *Config, db *sql.DB, assets fs.FS) *chi.Mux {
go func(r *http.Request) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
- if err := UpdateStats(setContext(ctx), r); err != nil {
+ if err := storage.UpdateStats(setContext(ctx), r, cfg.Domain); err != nil {
slog.Error("updating stats", "error", err)
}
}(r)