Skip to content

Instantly share code, notes, and snippets.

@LarryBattleWork
Created September 16, 2016 20:12
Show Gist options
  • Save LarryBattleWork/dd38b88c4861ecf06a6c4de7cfc064b7 to your computer and use it in GitHub Desktop.
Save LarryBattleWork/dd38b88c4861ecf06a6c4de7cfc064b7 to your computer and use it in GitHub Desktop.
View the headers of a request
// Works with Golang 1.7
// Run `go run server.go` and then visit the url shown
package main
import (
"fmt"
"net/http"
)
const PORT = "8080"
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Look in the terminal")
fmt.Println("\n\n#### New request ####")
for k, v := range r.Header {
fmt.Println(k, ": ", v)
}
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("To view the to http://localhost:" + PORT )
http.ListenAndServe(":"+PORT, nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment