commit 3370271083208975489d82da6cc01386879cf1ee
parent d808b53777fbcf020bfe14ddfd4210b0397f4baf
Author: Vetle Haflan <vetle@haflan.dev>
Date: Mon, 12 Apr 2021 19:55:54 +0200
Add glogserver.go
Diffstat:
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/glogserver.go b/glogserver.go
@@ -0,0 +1,34 @@
+package main
+
+// glogserver simply takes any request and prints it.
+// Often useful for debugging stuff.
+
+import (
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+)
+
+func main() {
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ b, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ log.Print("error:", err)
+ }
+ defer r.Body.Close()
+ log.Printf("%v %v\n", r.Method, r.RequestURI)
+ if len(b) > 0 {
+ log.Println("-<body>-----------------------------")
+ log.Println(string(b))
+ log.Println("------------------------------------")
+ }
+ })
+ port := ":3000"
+ if len(os.Args) == 2 {
+ port = fmt.Sprintf(":%v", os.Args[1])
+ }
+ log.Println("Starting server at", port)
+ log.Fatal(http.ListenAndServe(port, nil))
+}