Skip to content

Instantly share code, notes, and snippets.

@Daniel1984
Created April 25, 2020 14:41
Show Gist options
  • Save Daniel1984/5b2aa966f5c91a81d63622819fe39b2e to your computer and use it in GitHub Desktop.
Save Daniel1984/5b2aa966f5c91a81d63622819fe39b2e to your computer and use it in GitHub Desktop.
// pkg/middleware/logging.go
package middleware
import (
"net/http"
"github.com/boilerplate/pkg/logger"
"github.com/julienschmidt/httprouter"
)
func LogRequest(next httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
logger.Info.Printf("%s - %s %s %s", r.RemoteAddr, r.Proto, r.Method, r.URL.RequestURI())
next(w, r, p)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment