Last active
August 29, 2015 14:08
-
-
Save doug/717966d85b3895d1a644 to your computer and use it in GitHub Desktop.
yep nope http handler
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
package yepnope | |
import ( | |
"net/http" | |
) | |
func YepNope(test func(r *http.Request) bool, yep http.Handler, nope http.Handler) http.Handler { | |
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | |
if test(r) { | |
yep.ServeHTTP(rw, r) | |
return | |
} | |
nope.ServeHTTP(rw, r) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment