Created
July 14, 2021 09:04
-
-
Save tuannvm/f6aa19275322e9a62bf4d6ca0f794971 to your computer and use it in GitHub Desktop.
#go #http #server #debug #troubleshoot
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" | |
"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