Skip to content

Instantly share code, notes, and snippets.

@tuannvm
Created July 14, 2021 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuannvm/f6aa19275322e9a62bf4d6ca0f794971 to your computer and use it in GitHub Desktop.
Save tuannvm/f6aa19275322e9a62bf4d6ca0f794971 to your computer and use it in GitHub Desktop.
#go #http #server #debug #troubleshoot
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/gorilla/mux"
)
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to the HomePage!")
fmt.Println("Endpoint Hit: homePage")
for name, values := range r.Header {
// Loop over all values for the name.
for _, value := range values {
fmt.Println(name, value)
}
}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
fmt.Println(bodyString)
}
func main() {
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/v2/trace", homePage)
log.Fatal(http.ListenAndServe(":8080", myRouter))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment