forked from mtusi2026/mtusi2026lab3
chore(solution): pull lab2 solution
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user