Skip to content

Commit

Permalink
validation
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Jun 7, 2024
1 parent 806c217 commit bacb230
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"unicode"
)

Expand All @@ -38,6 +39,7 @@ var Validators = map[*regexp.Regexp]func(match []string, value *generic.Value) e
regexp.MustCompile(`^domain$`): domainValidator,
regexp.MustCompile(`^url$`): urlValidator,
regexp.MustCompile(`^ip$`): ipValidator,
regexp.MustCompile(`^date$`): dateValidator,
}

var enumRegex = regexp.MustCompile(`(?m)enum\(([^)]+)\)`)
Expand Down Expand Up @@ -390,3 +392,11 @@ func regexValidator(match []string, value *generic.Value) error {
}
return nil
}

func dateValidator(match []string, value *generic.Value) error {
_, err := time.Parse(time.RFC3339, value.String())
if err != nil {
return fmt.Errorf("invalid date, date expected be in RFC3339 format")
}
return nil
}

0 comments on commit bacb230

Please sign in to comment.