Created
September 16, 2016 20:12
-
-
Save LarryBattleWork/dd38b88c4861ecf06a6c4de7cfc064b7 to your computer and use it in GitHub Desktop.
View the headers of a request
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
// 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