internal/httpd/confirm.go
26 lines · 637 bytes
1package httpd
2
3import (
4 "net/http"
5 "strings"
6)
7
8// confirmed reports whether the form typed want into its confirm field.
9// It guards controls that destroy data nothing else holds; the person
10// is already authorised, so this is a check against a slip, not a
11// permission.
12func confirmed(r *http.Request, want string) (bool, string) {
13 if strings.TrimSpace(r.FormValue("confirm")) == want {
14 return true, ""
15 }
16 return false, "type " + want + " to confirm"
17}
18
19// prefix8 returns s truncated to its first 8 characters, or s unchanged
20// if it is shorter.
21func prefix8(s string) string {
22 if len(s) > 8 {
23 return s[:8]
24 }
25 return s
26}