Skip to content

Instantly share code, notes, and snippets.

@juliusmh
Created April 19, 2022 14:41
Show Gist options
  • Save juliusmh/3ea64bc0e192bf15bb47f47828908fd5 to your computer and use it in GitHub Desktop.
Save juliusmh/3ea64bc0e192bf15bb47f47828908fd5 to your computer and use it in GitHub Desktop.
Serve HTTP 200 to any incoming request and print path, method and request body.
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)
func main() {
port := flag.Int("port", 9000, "port to listen on")
flag.Parse()
http.HandleFunc("/", handler)
http.ListenAndServe(":" + strconv.Itoa(*port), nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
b, _ := ioutil.ReadAll(r.Body)
if len(b) > 0 {
b = append(b, '\n')
}
fmt.Printf("%s %s\n%s\n", r.Method, r.URL.Path, string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment