lab2: postgres, sessions, redis, persistence, stale read
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-09 21:30:36 +03:00
parent 65003b6119
commit d8842a3de4
54 changed files with 3205 additions and 19 deletions
+48
View File
@@ -0,0 +1,48 @@
package service
import (
"regexp"
"strings"
"unicode/utf8"
)
var usernameRe = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
func validatePassword(s string) bool {
n := utf8.RuneCountInString(s)
return n >= 12 && n <= 128
}
// validateUsername проверяет формат username по README: строго [a-z0-9_]{3,32}.
func validateUsername(s string) bool {
return usernameRe.MatchString(s)
}
// validateDisplayName проверяет display_name: 1–100 Unicode code points,
// не состоит только из пробельных символов.
func validateDisplayName(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateTitle проверяет title чата: 1–100 code points, не только пробелы.
func validateTitle(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateText проверяет text сообщения: 1–4000 code points, не только пробелы.
// В lab4 появится возможность отправить пустой text, если есть attachment_ids.
func validateText(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 4000
}