Skip to content

Instantly share code, notes, and snippets.

@papisz
Last active July 5, 2018 20:22
Show Gist options
  • Save papisz/aac3559c556acb7a14ee8cc0869e4193 to your computer and use it in GitHub Desktop.
Save papisz/aac3559c556acb7a14ee8cc0869e4193 to your computer and use it in GitHub Desktop.
chi-urlparam-checking-get
r.Get("/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