Skip to content

Instantly share code, notes, and snippets.

@papisz
Last active July 5, 2018 21:00
Show Gist options
  • Save papisz/d2a0c5c09d10689daa0612f20fde1ed7 to your computer and use it in GitHub Desktop.
Save papisz/d2a0c5c09d10689daa0612f20fde1ed7 to your computer and use it in GitHub Desktop.
chi-urlparam-simplest
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