Created
May 22, 2020 12:25
-
-
Save jgengo/9963696a24a1b9a6372c612e24fd81f0 to your computer and use it in GitHub Desktop.
small / tiny web server to test my clients
This file contains 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 ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "%s %s %s\n", r.Method, r.URL, r.Proto) | |
for k, v := range r.Header { | |
fmt.Fprintf(w, "Header[%q] = %q\n", k, v) | |
} | |
fmt.Fprintf(w, "Host = %q\n", r.Host) | |
fmt.Fprintf(w, "RemoteAddr = %q\n", r.RemoteAddr) | |
if err := r.ParseForm(); err != nil { | |
log.Println(err) | |
} | |
for k, v := range r.Form { | |
fmt.Fprintf(w, "Form[%q] = %q\n", k, v) | |
} | |
} | |
func main() { | |
http.HandleFunc("/", handler) | |
log.Fatal(http.ListenAndServe("localhost:3030", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment