Use github.com/julienschmidt/httprouter instead of gorilla
This commit is contained in:
parent
0f9c3510cd
commit
5837e0e594
13 changed files with 223 additions and 169 deletions
|
|
@ -3,16 +3,42 @@ package main
|
|||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/api"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
type staticRouting struct {
|
||||
StaticDir string
|
||||
}
|
||||
func init() {
|
||||
api.Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
})
|
||||
api.Router().GET("/exercices/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
})
|
||||
api.Router().GET("/events/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
})
|
||||
api.Router().GET("/teams/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
})
|
||||
api.Router().GET("/themes/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
})
|
||||
|
||||
func StaticHandler(staticDir string) http.Handler {
|
||||
return staticRouting{staticDir}
|
||||
}
|
||||
|
||||
func (a staticRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, path.Join(a.StaticDir, "index.html"))
|
||||
api.Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue