Skip to content

Instantly share code, notes, and snippets.

@papisz
Last active July 5, 2018 20:22
Show Gist options
  • Save papisz/0e914bffdbd8075a8da4da629cfea3db to your computer and use it in GitHub Desktop.
Save papisz/0e914bffdbd8075a8da4da629cfea3db to your computer and use it in GitHub Desktop.
chi-urlparam-checking-put
r.Put("/info", func(w http.ResponseWriter, r *http.Request) {
pet := chi.URLParam(r, "pet")
forbiddenPets := []string{"dragon"}
for _, forbiddenPet := range forbiddenPets {
if pet == forbiddenPet {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("forbidden pet %s!\n", pet)))
return
}
}
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