Skip to content

Instantly share code, notes, and snippets.

@jinuljt
Last active August 29, 2015 14:25
Show Gist options
  • Save jinuljt/00491b8bf6d7166d3842 to your computer and use it in GitHub Desktop.
Save jinuljt/00491b8bf6d7166d3842 to your computer and use it in GitHub Desktop.
go form validate
package forms
import "github.com/gorilla/schema"
import "github.com/go-validator/validator"
var decoder = schema.NewDecoder()
func Validate(
dst interface{},
values map[string][]string) (bool, map[string][]error) {
decoder.Decode(dst, values)
return validator.Validate(dst)
}
type PersonForm struct {
Name string `schema:"name" validate:"nonzero"`
Age int `schema:"age" validate:"nonzero"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment