Skip to content

Instantly share code, notes, and snippets.

@sklyar
Last active March 26, 2020 13:39
Show Gist options
  • Save sklyar/fa5150190a13bc79a550e09aecd97e18 to your computer and use it in GitHub Desktop.
Save sklyar/fa5150190a13bc79a550e09aecd97e18 to your computer and use it in GitHub Desktop.
golang trace http requests
package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"github.com/sirupsen/logrus"
)
func main() {
logrus.SetLevel(logrus.TraceLevel)
host := flag.String("host", "127.0.0.1:3108", "127.0.0.1:3108")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
b, err := httputil.DumpRequest(r, true)
if err != nil {
logrus.Errorf("can`t make dump request: %v", err)
}
logrus.Tracef("GET: \n%s", b)
})
logrus.Fatal(http.ListenAndServe(*host, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment