Files
Crussell/backend/internal/validators/validators.go
T
popertots a4a80246d1
CI / Env docs check (push) Successful in 14s
CI / Docker compose check (push) Successful in 20s
CI / Nginx config check (push) Successful in 20s
CI / Frontend major deps (push) Failing after 30s
CI / Frontend deps check (push) Successful in 31s
CI / Secrets scan (push) Successful in 38s
CI / Go build (push) Successful in 38s
CI / Frontend build (push) Successful in 42s
CI / Knip (push) Successful in 40s
CI / Frontend a11y check (push) Successful in 2m2s
CI / Go vet (prod) (push) Successful in 1m56s
CI / Go vet (dev) (push) Successful in 2m7s
CI / Staticcheck (prod) (push) Successful in 2m51s
CI / Staticcheck (dev) (push) Successful in 3m3s
CI / go mod tidy (push) Successful in 1m17s
CI / Frontend QC (audit) (push) Successful in 1m34s
CI / golangci-lint (push) Successful in 3m44s
CI / Go vulnerabilities (push) Successful in 2m10s
CI / Frontend QC (typecheck) (push) Successful in 1m29s
CI / Security scan (prod) (push) Successful in 4m3s
CI / Security scan (dev) (push) Successful in 4m37s
CI / Frontend QC (lint) (push) Successful in 1m40s
CI / Svelte strict check (push) Successful in 1m22s
CI / Tests (prod) (push) Successful in 3m12s
CI / Tests (dev) (push) Successful in 3m32s
CI / Race (prod) (push) Successful in 7m12s
CI / Race (dev) (push) Successful in 7m22s
fix: restore S3 error stubs, add CI timeouts, gofmt handlers.go, fix comment
- s3.go: restore error returns on prod Upload/Download/Delete stubs
  (silent nil was dangerous — callers would think writes succeeded)
- CI: add -timeout 300s to tests, -timeout 480s to race, GO_TESTING to race env
- handlers.go: gofmt indentation fix for GetCheckoutStatus struct literal
- validators.go: fix comment to include A-F (matched the regex)
2026-07-10 20:39:17 +01:00

66 lines
1.7 KiB
Go

package validators
import (
"fmt"
"github.com/go-playground/validator/v10"
"reflect"
"regexp"
"strconv"
"strings"
"time"
)
var Validate *validator.Validate
func init() {
Validate = validator.New()
Validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})
}
// ID format: 12-character hexadecimal string (from gen_random_bytes(6) encoded as hex)
var validIDRegex = regexp.MustCompile(`^[0-9a-fA-F]{12}$`)
// IsValidID checks if an ID is valid based on the database constraint (CHAR(12) hex string)
// Valid IDs are exactly 12 hexadecimal characters (0-9, a-f, A-F)
func IsValidID(id string) bool {
if id == "" {
return false
}
return validIDRegex.MatchString(id)
}
// ParseCursor splits a "createdAt|id" cursor string into its components.
func ParseCursor(cursor string) (time.Time, string, error) {
parts := strings.SplitN(cursor, "|", 2)
if len(parts) != 2 {
return time.Time{}, "", fmt.Errorf("invalid cursor format")
}
t, err := time.Parse(time.RFC3339, parts[0])
if err != nil {
return time.Time{}, "", fmt.Errorf("invalid cursor created_at: %w", err)
}
return t, parts[1], nil
}
func ParseCursor3(cursor string) (int, time.Time, string, error) {
parts := strings.SplitN(cursor, "|", 3)
if len(parts) != 3 {
return 0, time.Time{}, "", fmt.Errorf("invalid cursor format")
}
count, err := strconv.Atoi(parts[0])
if err != nil {
return 0, time.Time{}, "", fmt.Errorf("invalid cursor completed_count: %w", err)
}
t, err := time.Parse(time.RFC3339, parts[1])
if err != nil {
return 0, time.Time{}, "", fmt.Errorf("invalid cursor created_at: %w", err)
}
return count, t, parts[2], nil
}