O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Install github.com/asaskevich/govalidator and the github.com/gorilla/schema package using the go get command, as follows:
$ go get github.com/asaskevich/govalidator$ go get github.com/gorilla/schema
  1. Create html-form-validation.go, where we will read an HTML form, decode it using github.com/gorilla/schema, and validate each field of it against a tag defined in the User struct using github.com/asaskevich/govalidator, as follows:
package mainimport (  "fmt"  "html/template"  "log"  "net/http"  "github.com/asaskevich/govalidator"  "github.com/gorilla/schema")const (  CONN_HOST = "localhost"  CONN_PORT = "8080"  USERNAME_ERROR_MESSAGE = "Please enter a valid Username"  PASSWORD_ERROR_MESSAGE = "Please enter a valid Password" GENERIC_ERROR_MESSAGE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required