refactor services to use Interface and change name to app

This commit is contained in:
Robin Olsen
2026-02-22 16:16:09 +01:00
parent dbf619a054
commit 118e67dbf4
36 changed files with 247 additions and 219 deletions

View File

@@ -11,14 +11,14 @@ import (
type contextKey string
const (
servicesKey contextKey = "services"
htmxKey contextKey = "htmx"
appKey contextKey = "app"
htmxKey contextKey = "htmx"
)
func ServicesMiddleware(svc *service.Services) func(http.Handler) http.Handler {
func AppMiddleware(app *service.App) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), servicesKey, svc)
ctx := context.WithValue(r.Context(), appKey, app)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
@@ -33,8 +33,8 @@ func HTMXMiddleware(next http.Handler) http.Handler {
})
}
func Services(r *http.Request) *service.Services {
return r.Context().Value(servicesKey).(*service.Services)
func App(r *http.Request) *service.App {
return r.Context().Value(appKey).(*service.App)
}
func HTMX(r *http.Request) *htmx.Handler {