How to do it…

Let's implement logging using Gorilla handlers. Perform the following steps:

  1. Install the and packages using the go get command, as follows:
$ go get$ go get
  1. Create http-server-request-logging.go and copy the following content:
package mainimport (  "net/http"  "os"  ""  "")const (  CONN_HOST = "localhost"  CONN_PORT = "8080")var GetRequestHandler = http.HandlerFunc(  func(w http.ResponseWriter, r *http.Request)   {    w.Write([]byte("Hello World!"))  })var PostRequestHandler = http.HandlerFunc(  func(w http.ResponseWriter, r *http.Request)   {    w.Write([]byte("It's a Post Request!"))  })

Get Go Web Development Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.