Last active
March 26, 2020 13:39
-
-
Save sklyar/fa5150190a13bc79a550e09aecd97e18 to your computer and use it in GitHub Desktop.
golang trace http requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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