Created
April 19, 2022 14:41
-
-
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.
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 ( | |
"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