Let's implement logging using Gorilla handlers. Perform the following steps:
- 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
- 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!")) } ...