This commit is contained in:
lbenedar
2026-03-06 16:05:24 +03:00
parent 8d3c025660
commit fc07515dbd
2 changed files with 2 additions and 2 deletions

View File

@@ -111,7 +111,7 @@ func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request
form.CheckField(validator.NotBlank(form.Title), "title", "This field cannot be blank")
form.CheckField(validator.MaxChars(form.Title, 100), "title", "This field cannot be more than 100 character long")
form.CheckField(validator.NotBlank(form.Content), "content", "This field cannot be blank")
form.CheckField(validator.PermittedInt(form.Expires, 1, 7, 365), "expires", "This field must equal 1, 7 and 365")
form.CheckField(validator.PermittedValue(form.Expires, 1, 7, 365), "expires", "This field must equal 1, 7 and 365")
if !form.Valid() {
data := app.newTemplateData(r)

View File

@@ -42,7 +42,7 @@ func MaxChars(value string, n int) bool {
return utf8.RuneCountInString(value) <= n
}
func PermittedInt(value int, permittedValues ...int) bool {
func PermittedValue[T comparable](value T, permittedValues ...T) bool {
for i := range permittedValues {
if value == permittedValues[i] {
return true