How to do it...

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

  1. Install the github.com/gorilla/handler and github.com/gorilla/mux packages using the go get command, as follows:
$ go get github.com/gorilla/handlers$ go get github.com/gorilla/mux
  1. Create http-server-request-logging.go and copy the following content:
package mainimport (  "net/http"  "os"  "github.com/gorilla/handlers"  "github.com/gorilla/mux")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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.