Files
cv-site/internal/httputil/method.go
T
juanatsap 2c7f8de242 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)
2025-12-06 16:27:12 +00:00

26 lines
746 B
Go

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)
}