package main import ( "log" "net/http" "github.com/fatih/color" ) var MethodColors = map[string]*color.Color{ "GET": color.New(color.FgBlue), "POST": color.New(color.FgGreen), "PUT": color.New(color.FgYellow), "DELETE": color.New(color.FgRed), } func MethodToString(method string) string { if str, ok := MethodColors[method]; ok { return str.Sprint(method) } return method } func LogHandler(handler http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { log.Printf("%s %s", MethodToString(r.Method), r.URL.String()) handler.ServeHTTP(w, r) } }