Last active
August 29, 2015 14:24
-
-
Save mikeflynn/1b473a8a9e8b1659eaf7 to your computer and use it in GitHub Desktop.
Example mux setup.
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" | |
"github.com/codegangsta/negroni" | |
"github.com/gorilla/mux" | |
) | |
func main() { | |
router := mux.NewRouter() | |
pageRouter := PageRouter() | |
router.PathPrefix("/").Handler(negroni.New( | |
negroni.Wrap(pageRouter), | |
)) | |
apiRouter := APIRouter() | |
router.PathPrefix("/api/").Handler(negroni.New( | |
negroni.HandlerFunc(ValidateRequest), | |
negroni.Wrap(apiRouter), | |
)) | |
n := negroni.Classic() | |
n.UseHandler(router) | |
n.Run(":3000") | |
} | |
func PageRouter() *mux.Router { | |
router := mux.NewRouter() | |
router.HandleFunc("/", homePage) | |
router.HandleFunc("/about", aboutPage) | |
return router | |
} | |
func APIRouter() *mux.Router { | |
router := mux.NewRouter() | |
router.HandleFunc("/", apiTest) | |
router.HandleFunc("/test", apiTest) | |
return router | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment