Skip to content

Instantly share code, notes, and snippets.

@DaisukeMiyamoto
Created November 7, 2017 05:50
Show Gist options
  • Select an option

  • Save DaisukeMiyamoto/77fef17e310f8b9ea2c3f4e44f3b8b2d to your computer and use it in GitHub Desktop.

Select an option

Save DaisukeMiyamoto/77fef17e310f8b9ea2c3f4e44f3b8b2d to your computer and use it in GitHub Desktop.
from real world http example
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