add middlewares, handlers and database models
This commit is contained in:
parent
979a415b95
commit
7e288ea67a
24 changed files with 1045 additions and 14 deletions
19
internal/middleware/config.go
Normal file
19
internal/middleware/config.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.juancwu.dev/juancwu/budgething/internal/config"
|
||||
"git.juancwu.dev/juancwu/budgething/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))
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue