Last active
July 5, 2018 20:22
-
-
Save papisz/0e914bffdbd8075a8da4da629cfea3db to your computer and use it in GitHub Desktop.
chi-urlparam-checking-put
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
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