chore(solution): port lab3 sources

This commit is contained in:
2026-11-20 03:05:34 +03:00
parent ec540a1a72
commit 083d0d80cc
44 changed files with 2745 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
package service
import (
"fmt"
"strings"
"unicode/utf8"
"messenger/internal/domain"
)
const (
DefaultLimit = 50
MaxLimit = 100
)
func checkText(field, value string, maxRunes int) error {
if strings.TrimSpace(value) == "" {
return fmt.Errorf("%w: %s must not be empty", domain.ErrInvalidInput, field)
}
if n := utf8.RuneCountInString(value); n > maxRunes {
return fmt.Errorf("%w: %s must be at most %d characters", domain.ErrInvalidInput, field, maxRunes)
}
return nil
}
func checkLimit(limit int) error {
if limit < 1 || limit > MaxLimit {
return fmt.Errorf("%w: limit must be between 1 and %d", domain.ErrInvalidInput, MaxLimit)
}
return nil
}