forked from mtusi2026/mtusi2026lab5
ЛР 5: асинхронная обработка изображений, уровень 5
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user