start work on federationinfo

This commit is contained in:
Michael Jerger 2024-01-12 14:33:52 +01:00
parent 12558d62c8
commit 8610d94af8
4 changed files with 58 additions and 1 deletions

View file

@ -6,6 +6,7 @@ package validation
import (
"fmt"
"strings"
"unicode/utf8"
)
type Validateable interface {
@ -21,13 +22,20 @@ func IsValid(v Validateable) (bool, error) {
return true, nil
}
func ValidateNotEmpty(value, fieldName string) []string {
func ValidateNotEmpty(value string, fieldName string) []string {
if value == "" {
return []string{fmt.Sprintf("Field %v may not be empty", fieldName)}
}
return []string{}
}
func ValidateMaxLen(value string, maxLen int, fieldName string) []string {
if utf8.RuneCountInString(value) > maxLen {
return []string{fmt.Sprintf("Value in field %v was longer than %v", fieldName, maxLen)}
}
return []string{}
}
func ValidateOneOf(value any, allowed []any) []string {
for _, allowedElem := range allowed {
if value == allowedElem {