forked from mtusi2026/mtusi2026lab3
внес правки
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"mtusi2026/internal/idgen"
|
||||
)
|
||||
|
||||
func validText(s string, max int) bool {
|
||||
n := utf8.RuneCountInString(s)
|
||||
if n < 1 || n > max {
|
||||
return false
|
||||
}
|
||||
hasContent := false
|
||||
for _, r := range s {
|
||||
if r == 0 {
|
||||
return false
|
||||
}
|
||||
if !unicode.IsSpace(r) {
|
||||
hasContent = true
|
||||
}
|
||||
}
|
||||
return hasContent
|
||||
}
|
||||
|
||||
func parseCursor(r *http.Request) (string, bool) {
|
||||
q := r.URL.Query()
|
||||
if !q.Has("cursor") {
|
||||
return "", true
|
||||
}
|
||||
c := q.Get("cursor")
|
||||
return c, c != ""
|
||||
}
|
||||
|
||||
func chatIDParam(w http.ResponseWriter, r *http.Request, requestID string) (string, bool) {
|
||||
id := r.PathValue("chat_id")
|
||||
if !idgen.IsValidUUID(id) {
|
||||
writeError(w, http.StatusBadRequest, requestID, codeInvalidRequest, "invalid chat_id")
|
||||
return "", false
|
||||
}
|
||||
return strings.ToLower(id), true
|
||||
}
|
||||
Reference in New Issue
Block a user