ЛР 6 — БПИ2302 — Нурлыгаянова — на 3

This commit is contained in:
Nurlygayanova Ekaterina
2026-11-13 11:32:45 +03:00
parent 470d9d6f1e
commit 69a190be0e
164 changed files with 25947 additions and 29 deletions
+42
View File
@@ -0,0 +1,42 @@
package validate
import "fmt"
func ChatTitle(s string) error {
if !notOnlyWhitespace(s) {
return newError("title", "must not be empty or whitespace only")
}
if !codePointsBetween(s, ChatTitleMinLen, ChatTitleMaxLen) {
return newError("title", fmt.Sprintf("length must be in [%d, %d] code points", ChatTitleMinLen, ChatTitleMaxLen))
}
return nil
}
func MemberIDs(ids []string, callerID string) ([]string, error) {
if len(ids) < MemberIDsMin || len(ids) > MemberIDsMax {
return nil, newError("member_ids", fmt.Sprintf("count must be in [%d, %d]", MemberIDsMin, MemberIDsMax))
}
out := make([]string, 0, len(ids))
seen := make(map[string]struct{}, len(ids))
callerIn := false
for i, raw := range ids {
id, err := CanonicalUUID(fmt.Sprintf("member_ids[%d]", i), raw)
if err != nil {
return nil, err
}
if _, dup := seen[id]; dup {
return nil, newError("member_ids", "must not contain duplicates")
}
seen[id] = struct{}{}
if id == callerID {
callerIn = true
}
out = append(out, id)
}
if !callerIn {
return nil, newError("member_ids", "must contain caller")
}
return out, nil
}