Created
September 8, 2019 16:33
-
-
Save codenoid/ae85414fb31af738581a06e2c6a94da9 to your computer and use it in GitHub Desktop.
before_request.go
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
package main | |
import ( | |
"log" | |
"net/http" | |
) | |
import ( | |
"github.com/julienschmidt/httprouter" | |
) | |
type BeforeRequest map[int]http.Handler | |
func (hs BeforeRequest) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
// your logic check | |
// ... | |
// ... | |
// to stop the handler, use redirect and return | |
// handle the request. | |
hs[0].ServeHTTP(w, r) | |
} | |
func index(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
} | |
func main() { | |
router := httprouter.New() | |
// Index | |
router.GET("/", index) | |
hs := make(BeforeRequest) | |
hs[0] = router | |
log.Fatal(http.ListenAndServe("0.0.0.0:2020", hs)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment