Created
April 26, 2018 20:24
-
-
Save bobbytables/6f78beeeaf85293f0fc92b0b466a2af0 to your computer and use it in GitHub Desktop.
A dumb little HTTP server to print headers easily using a tabwriter.
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 ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"strings" | |
"text/tabwriter" | |
) | |
func main() { | |
addr := os.Getenv("ADDR") | |
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | |
tabber := tabwriter.NewWriter(w, 2, 2, 1, ' ', 0) | |
fmt.Fprintf(tabber, "PATH\t%s\n", req.URL.Path) | |
fmt.Fprintf(tabber, "METHOD\t%s\n", req.Method) | |
for key, values := range req.Header { | |
fmt.Fprintf(tabber, "%s\t%s\n", key, strings.Join(values, ", ")) | |
} | |
tabber.Flush() | |
}) | |
log.Println("Starting server") | |
if err := http.ListenAndServe(addr, http.DefaultServeMux); err != nil { | |
log.Fatal(err.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment