package http import ( "encoding/json" "fmt" "net/http" ) type ( NotFound struct { } NotAllowed struct { } ) func (n NotFound) ServeHTTP(writer http.ResponseWriter, request *http.Request) { writer.WriteHeader(http.StatusNotFound) json.NewEncoder(writer).Encode(responsePayload{ Code: http.StatusNotFound, Reason: fmt.Sprintf("requested URL %s was not found on this server", request.URL.Path), }) } func (n NotAllowed) ServeHTTP(writer http.ResponseWriter, request *http.Request) { writer.WriteHeader(http.StatusMethodNotAllowed) json.NewEncoder(writer).Encode(responsePayload{ Code: http.StatusMethodNotAllowed, Reason: fmt.Sprintf("%s URL %s was not allow on this server", request.Method, request.URL.Path), }) }