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