Created
November 7, 2017 05:50
-
-
Save DaisukeMiyamoto/77fef17e310f8b9ea2c3f4e44f3b8b2d to your computer and use it in GitHub Desktop.
from real world http example
This file contains hidden or 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 ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "net/http/httputil" | |
| ) | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| dump, err := httputil.DumpRequest(r, true) | |
| if err != nil { | |
| http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) | |
| return | |
| } | |
| fmt.Println(string(dump)) | |
| fmt.Fprintf(w, "<html><body>hello</body></html>\n") | |
| } | |
| func main() { | |
| var httpServer http.Server | |
| http.HandleFunc("/", handler) | |
| log.Println("start http listening :18888") | |
| httpServer.Addr = ":18888" | |
| log.Println(httpServer.ListenAndServe()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment