ch13.2
This commit is contained in:
@@ -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.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.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.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() {
|
if !form.Valid() {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func MaxChars(value string, n int) bool {
|
|||||||
return utf8.RuneCountInString(value) <= n
|
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 {
|
for i := range permittedValues {
|
||||||
if value == permittedValues[i] {
|
if value == permittedValues[i] {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user