refactor: modernize Go idioms across codebase
Replace map[string]interface{} with map[string]any, ioutil.ReadAll with
io.ReadAll, and simplify redundant fmt.Sprintf/w.Write calls.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8933055358
commit
439dc2cd07
7 changed files with 28 additions and 34 deletions
10
change.go
10
change.go
|
|
@ -33,7 +33,7 @@ func checkPasswdConstraint(password string) error {
|
|||
func changePassword(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" && !changeLimiter.Allow(remoteIP(r)) {
|
||||
csrfToken, _ := setCSRFToken(w)
|
||||
displayTmplError(w, http.StatusTooManyRequests, "change.html", map[string]interface{}{"error": "Too many requests. Please try again later.", "csrf_token": csrfToken})
|
||||
displayTmplError(w, http.StatusTooManyRequests, "change.html", map[string]any{"error": "Too many requests. Please try again later.", "csrf_token": csrfToken})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -43,25 +43,25 @@ func changePassword(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
displayTmpl(w, "change.html", map[string]interface{}{"csrf_token": csrfToken})
|
||||
displayTmpl(w, "change.html", map[string]any{"csrf_token": csrfToken})
|
||||
return
|
||||
}
|
||||
|
||||
if !validateCSRF(r) {
|
||||
csrfToken, _ := setCSRFToken(w)
|
||||
displayTmplError(w, http.StatusForbidden, "change.html", map[string]interface{}{"error": "Invalid or missing CSRF token. Please try again.", "csrf_token": csrfToken})
|
||||
displayTmplError(w, http.StatusForbidden, "change.html", map[string]any{"error": "Invalid or missing CSRF token. Please try again.", "csrf_token": csrfToken})
|
||||
return
|
||||
}
|
||||
|
||||
if !validateAltcha(r) {
|
||||
csrfToken, _ := setCSRFToken(w)
|
||||
displayTmplError(w, http.StatusForbidden, "change.html", map[string]interface{}{"error": "Invalid or missing altcha response. Please try again.", "csrf_token": csrfToken})
|
||||
displayTmplError(w, http.StatusForbidden, "change.html", map[string]any{"error": "Invalid or missing altcha response. Please try again.", "csrf_token": csrfToken})
|
||||
return
|
||||
}
|
||||
|
||||
renderError := func(status int, msg string) {
|
||||
csrfToken, _ := setCSRFToken(w)
|
||||
displayTmplError(w, status, "change.html", map[string]interface{}{"error": msg, "csrf_token": csrfToken})
|
||||
displayTmplError(w, status, "change.html", map[string]any{"error": msg, "csrf_token": csrfToken})
|
||||
}
|
||||
|
||||
// Check the two new passwords are identical
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue