refactor: centralize constants and reorganize documentation
- Create internal/constants package with all hardcoded values (environment, cookies, themes, headers, routes, cache) - Create internal/httputil package for HTTP helper functions - Update all handlers and middleware to use centralized constants - Reorganize documentation with numbered prefixes (00-26) - Remove duplicate docs from validation folder and docs/ - Delete handlers/constants.go (moved to internal/constants)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RequireMethod checks if the request method matches expected.
|
||||
// Returns true if method matches, false otherwise (sends 405 error).
|
||||
func RequireMethod(w http.ResponseWriter, r *http.Request, method string) bool {
|
||||
if r.Method != method {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// RequirePost is a shorthand for RequireMethod(w, r, http.MethodPost).
|
||||
func RequirePost(w http.ResponseWriter, r *http.Request) bool {
|
||||
return RequireMethod(w, r, http.MethodPost)
|
||||
}
|
||||
|
||||
// RequireGet is a shorthand for RequireMethod(w, r, http.MethodGet).
|
||||
func RequireGet(w http.ResponseWriter, r *http.Request) bool {
|
||||
return RequireMethod(w, r, http.MethodGet)
|
||||
}
|
||||
Reference in New Issue
Block a user