Skip to content

Instantly share code, notes, and snippets.

@Zedd0202
Created January 13, 2020 01:30
Show Gist options
  • Save Zedd0202/163b1c04bb1128dcb702a2242fe98bf0 to your computer and use it in GitHub Desktop.
Save Zedd0202/163b1c04bb1128dcb702a2242fe98bf0 to your computer and use it in GitHub Desktop.
example 1-1
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
dump, error := httputil.DumpRequest(r, true)
if error != nil {
http.Error(w, fmt.Sprint(error), http.StatusInternalServerError)
return
}
fmt.Println(string(dump))
fmt.Fprint(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