Skip to content

Instantly share code, notes, and snippets.

@congjf
Created November 21, 2013 07:33
Show Gist options
  • Save congjf/7577396 to your computer and use it in GitHub Desktop.
Save congjf/7577396 to your computer and use it in GitHub Desktop.
static files routes in mux.go
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