veza/veza-backend-api/internal/utils/settings_validator.go
2025-12-03 20:29:37 +01:00

62 lines
1.5 KiB
Go

package utils
import (
"fmt"
"time"
)
// SupportedLanguages contains the list of supported ISO 639-1 language codes
var SupportedLanguages = []string{
"en", "fr", "es", "de", "it", "pt", "ru", "ja", "zh", "ko",
"ar", "hi", "nl", "sv", "pl", "tr", "cs", "ro", "hu", "fi",
}
// SupportedThemes contains the list of supported theme values
var SupportedThemes = []string{"light", "dark", "auto"}
// ValidateLanguage validates an ISO 639-1 language code
// Returns nil if valid or empty, error otherwise
func ValidateLanguage(language string) error {
if language == "" {
return nil // Optional field
}
for _, lang := range SupportedLanguages {
if language == lang {
return nil
}
}
return fmt.Errorf("unsupported language code: %s. Supported: %v", language, SupportedLanguages)
}
// ValidateTimezone validates an IANA timezone string
// Returns nil if valid or empty, error otherwise
func ValidateTimezone(timezone string) error {
if timezone == "" {
return nil // Optional field
}
_, err := time.LoadLocation(timezone)
if err != nil {
return fmt.Errorf("invalid timezone: %s. Must be a valid IANA timezone", timezone)
}
return nil
}
// ValidateTheme validates a theme enum value
// Returns nil if valid or empty, error otherwise
func ValidateTheme(theme string) error {
if theme == "" {
return nil // Optional field
}
for _, t := range SupportedThemes {
if theme == t {
return nil
}
}
return fmt.Errorf("invalid theme: %s. Allowed: %v", theme, SupportedThemes)
}