forked from mtusi2026/mtusi2026lab5
15 lines
527 B
Go
15 lines
527 B
Go
package validate
|
|
|
|
import "fmt"
|
|
|
|
// MessageText: пустой или пробельный текст допустим, только если у сообщения есть вложения.
|
|
func MessageText(s string, hasAttachments bool) error {
|
|
if !hasAttachments && !notOnlyWhitespace(s) {
|
|
return newError("text", "must not be empty or whitespace only")
|
|
}
|
|
if !codePointsBetween(s, 0, MessageTextMaxLen) {
|
|
return newError("text", fmt.Sprintf("length must be at most %d code points", MessageTextMaxLen))
|
|
}
|
|
return nil
|
|
}
|