Skip to content

Instantly share code, notes, and snippets.

Created Feb 22, 2019
What would you like to do?
Not using context
package main
import (
// routeLog perform logging on a route, returning log.Interface if want to add more specific details
func routeLog(r *http.Request, info string) *log.Entry {
l := log.WithFields(log.Fields{
"method": r.Method,
"requestURI": r.RequestURI,
return l
func index(w http.ResponseWriter, r *http.Request) {
routeLog(r, "index")
fmt.Fprintf(w, "hello")
func about(w http.ResponseWriter, r *http.Request) {
routeLog(r, "about")
fmt.Fprintf(w, "about")
func main() {
app := mux.NewRouter()
app.HandleFunc("/", index)
app.HandleFunc("/about", about)
if err := http.ListenAndServe(":"+os.Getenv("PORT"), app); err != nil {
log.WithError(err).Fatal("error listening")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment