Skip to content

Instantly share code, notes, and snippets.

@kjmkznr
Created December 30, 2018 10:44
Show Gist options
  • Save kjmkznr/54f3de86a2ab241a792f66e9ea75beea to your computer and use it in GitHub Desktop.
Save kjmkznr/54f3de86a2ab241a792f66e9ea75beea to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"flag"
"io"
"log"
"net/http"
"strconv"
)
func handler(w http.ResponseWriter, r *http.Request) {
var buf bytes.Buffer
mw := io.MultiWriter(w, &buf)
r.Write(mw)
log.Print(buf.String())
}
func main() {
port := flag.Int("port", 8080, "Listen on port")
flag.Parse()
http.HandleFunc("/", handler)
log.Println("Starting http server on port:", *port)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment