Created
November 30, 2018 16:38
-
-
Save Bebbolus/6e872ae5346ce93c5d2fb99654742dd5 to your computer and use it in GitHub Desktop.
This file contains 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
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