Skip to content

Instantly share code, notes, and snippets.

@Bebbolus
Created November 30, 2018 16:38
Show Gist options
  • Save Bebbolus/6e872ae5346ce93c5d2fb99654742dd5 to your computer and use it in GitHub Desktop.
Save Bebbolus/6e872ae5346ce93c5d2fb99654742dd5 to your computer and use it in GitHub Desktop.
func pass(args string) func(http.HandlerFunc) http.HandlerFunc {
return func(f http.HandlerFunc) http.HandlerFunc {
// Define the http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
//split args and check if the request as this method
acceptedMethods := strings.Split(args, "|")
for _, v := range acceptedMethods {
if r.Method == v {
// Call the next middleware in chain
f(w, r)
return
}
}
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment