Last active
July 5, 2018 21:00
-
-
Save papisz/d2a0c5c09d10689daa0612f20fde1ed7 to your computer and use it in GitHub Desktop.
chi-urlparam-simplest
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
func serve() { | |
r := chi.NewRouter() | |
r.Route("/pets", func(r chi.Router) { | |
r.Route("/{pet}", func(r chi.Router) { | |
r.Get("/", getPetHandler) | |
r.Put("/", putPetHandler) | |
}) | |
}) | |
http.ListenAndServe(":8000", r) | |
} | |
func getPetHandler(w http.ResponseWriter, r *http.Request) { | |
pet := chi.URLParam(r, "pet") | |
w.Write([]byte(fmt.Sprintf("get pet: %s", pet))) | |
} | |
func putPetHandler(w http.ResponseWriter, r *http.Request) { | |
pet := chi.URLParam(r, "pet") | |
w.Write([]byte(fmt.Sprintf("put pet: %s", pet))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment