How to do it...

  1. Install the github.com/gorilla/mux package using the go get command, as follows:
$ go get github.com/gorilla/mux
  1. Create http-error-handling.go, where we will create a custom handler that acts as a wrapper to handle all the HTTP requests, as follows:
package mainimport (  "errors"  "fmt"  "log"  "net/http"  "strings"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost"  CONN_PORT = "8080")type NameNotFoundError struct {  Code int  Err error}func (nameNotFoundError NameNotFoundError) Error() string {  return nameNotFoundError.Err.Error()}type WrapperHandler func(http.ResponseWriter, *http.Request) errorfunc (wrapperHandler WrapperHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {  err := wrapperHandler(w, r) if err != ...

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.