Because bindform is aimed to only binding data, it does not cover data validations (only type checking). You should validate data after (or before) data binding.
go get -u github.com/harukasan/bindform/bindform
package main
import (
"net/http"
"github.com/harukasan/bindform/bindform"
type ContactForm struct {
Name string `form:"name"`
Email string `form:"email"`
Message string `form:"message"`
}
func HandlePostContactForm(w http.ResponseWriter, r *http.Request) {
form := &ContactForm{}
err := bindform.BindPostForm(r, form)
if err != nil {
http.Error(w, "Bad Request", 400)
}
// Debug print
// log.Println(form)
// needs more validations ...
}
- bool
- int
- uint
- float
- string
- Supports array type
- Supports require tag
Copyright (c) 2015, MICHII Shunsuke.
See License