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 the github.com/gorilla/schema package using the go get command, as follows:
$ go get github.com/gorilla/schema
  1. Create html-form-read.go, where we will read an HTML form field after decoding it using the github.com/gorilla/schema package and write Hello followed by the username to an HTTP response stream, as follows:
package mainimport (  "fmt"  "html/template"  "log"  "net/http"  "github.com/gorilla/schema")const (  CONN_HOST = "localhost"  CONN_PORT = "8080")type User struct {  Username string  Password string}func readForm(r *http.Request) *User {  r.ParseForm()  user := new(User)  decoder := schema.NewDecoder()  decodeErr := decoder.Decode(user, r.PostForm)  if decodeErr != nil   { log.Printf("error mapping parsed form data ...

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