start work on federationinfo
This commit is contained in:
parent
12558d62c8
commit
8610d94af8
4 changed files with 58 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue