Created
November 21, 2013 07:33
-
-
Save congjf/7577396 to your computer and use it in GitHub Desktop.
static files routes in mux.go
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 main | |
import ( | |
// native packages | |
"net/http" | |
// third packages | |
"github.com/gorilla/mux" // for router | |
) | |
func getRoutes() *mux.Router { | |
r := mux.NewRouter() | |
// static files routes | |
r.HandleFunc("/assets/{dirs}/{files}", serveFiles) | |
return r | |
} | |
func serveFiles(rw http.ResponseWriter, req *http.Request) { | |
http.ServeFile(rw, req, config.GetWD()+"/"+req.URL.Path[1:]) | |
} | |
func main() { | |
// map the routes | |
routes := getRoutes() | |
http.Handle("/", routes) | |
// server start | |
err := http.ListenAndServe(":8080", nil) | |
if err != nil { | |
aop.After(err.Error()) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment