budgit/internal/middleware/config.go
2025-12-16 10:50:16 -05:00

19 lines
597 B
Go

package middleware
import (
"net/http"
"git.juancwu.dev/juancwu/budgit/internal/config"
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
)
// Config middleware adds the sanitized app configuration to the request context.
// Sensitive values like JWTSecret and DBPath are excluded for security.
func Config(cfg *config.Config) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := ctxkeys.WithConfig(r.Context(), cfg.Sanitized())
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}