forked from mtusi2026/mtusi2026lab3
feat(app) lab 3 implemented
This commit is contained in:
@@ -8,7 +8,10 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var usernameRegex = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
|
||||
var (
|
||||
usernameRegex = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
|
||||
idempotencyKeyRegex = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,128}$`)
|
||||
)
|
||||
|
||||
func blank(s string) bool {
|
||||
return strings.TrimSpace(s) == ""
|
||||
@@ -71,6 +74,16 @@ func ValidateMessageText(text string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func ValidateIdempotencyKey(key string) string {
|
||||
if key == "" {
|
||||
return "Idempotency-Key header is required"
|
||||
}
|
||||
if !idempotencyKeyRegex.MatchString(key) {
|
||||
return "Idempotency-Key must match ^[A-Za-z0-9._:-]{1,128}$"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func ValidateMemberIDs(ids []uuid.UUID, callerID uuid.UUID) string {
|
||||
if len(ids) < 1 || len(ids) > 100 {
|
||||
return "member_ids must contain between 1 and 100 members"
|
||||
|
||||
Reference in New Issue
Block a user