removed resolved todos

This commit is contained in:
Michael Jerger 2023-12-22 14:20:30 +01:00
parent 2e031a9763
commit a64ce2feb1
3 changed files with 22 additions and 40 deletions

View file

@ -8,23 +8,12 @@ import (
"strings"
)
/*
type ValidationFunctions interface {
Validate() []string
IsValid() (bool, error)
}
type Validateable struct {
ValidationFunctions
}
*/
type Validateable interface {
Validate() []string
}
func IsValid(v any) (bool, error) {
if err := Validate(v); len(err) > 0 {
func IsValid(v Validateable) (bool, error) {
if err := v.Validate(); len(err) > 0 {
errString := strings.Join(err, "\n")
return false, fmt.Errorf(errString)
}
@ -32,7 +21,22 @@ func IsValid(v any) (bool, error) {
return true, nil
}
func Validate(v any) []string {
var result = []string{}
return result
func ValidateNotEmpty(value string, fieldName string) []string {
if value == "" {
return []string{fmt.Sprintf("Field %v may not be empty", fieldName)}
}
return []string{}
}
func ValidateOneOf(value string, allowed []string) []string {
for _, allowedElem := range allowed {
if value == allowedElem {
return []string{}
}
}
return []string{fmt.Sprintf("Value %v is not contained in allowed values [%v]", value, allowed)}
}
func ValidateSuffix(str, suffix string) bool {
return strings.HasSuffix(str, suffix)
}