Use gorilla/mux

This commit is contained in:
Las Zenow 2013-04-15 00:37:49 +02:00
parent 98d5074eff
commit 3a99f86f32
2 changed files with 25 additions and 21 deletions

2
README
View file

@ -25,7 +25,7 @@ Under Debian Wheezy you can simply run:
Yo also need to install go dependences: Yo also need to install go dependences:
# go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions github.com/gorilla/securecookie github.com/nfnt/resize # go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions github.com/gorilla/securecookie github.com/gorilla/mux github.com/nfnt/resize
== Installation == == Installation ==
=== For admins ("for developers" below) === === For admins ("for developers" below) ===

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"github.com/gorilla/mux"
"io" "io"
"labix.org/v2/mgo/bson" "labix.org/v2/mgo/bson"
"log" "log"
@ -130,29 +131,32 @@ func main() {
} }
/* set up web handlers */ /* set up web handlers */
http.HandleFunc("/book/", bookHandler) r := mux.NewRouter()
http.HandleFunc("/search/", searchHandler) r.HandleFunc("/", indexHandler)
http.HandleFunc("/upload/", uploadHandler) r.HandleFunc("/book/{id:[0-9a-fA-F]+}", bookHandler)
http.HandleFunc("/login/", loginHandler) r.HandleFunc("/search/{query}", searchHandler)
http.HandleFunc("/logout/", logoutHandler) r.HandleFunc("/upload/", uploadHandler)
http.HandleFunc("/new/", newHandler) r.HandleFunc("/login/", loginHandler)
http.HandleFunc("/store/", storeHandler) r.HandleFunc("/logout/", logoutHandler)
http.HandleFunc("/read/", readHandler) r.HandleFunc("/new/", newHandler)
http.HandleFunc("/content/", contentHandler) r.HandleFunc("/store/{ids:([0-9a-fA-F]+/)+}", storeHandler)
http.HandleFunc("/edit/", editHandler) r.HandleFunc("/delete/{ids:([0-9a-fA-F]+/)+}", deleteHandler)
http.HandleFunc("/save/", saveHandler) r.HandleFunc("/read/{id:[0-9a-fA-F]+}", readHandler)
http.HandleFunc("/delete/", deleteHandler) r.HandleFunc("/read/{id:[0-9a-fA-F]+}/{path}", readHandler)
http.HandleFunc("/about/", aboutHandler) r.HandleFunc("/content/{id:[0-9a-fA-F]+}/{path}", contentHandler)
http.HandleFunc("/books/", downloadHandler) r.HandleFunc("/edit/{id:[0-9a-fA-F]+}", editHandler)
http.HandleFunc("/settings/", settingsHandler) r.HandleFunc("/save/{id:[0-9a-fA-F]+}", saveHandler)
r.HandleFunc("/about/", aboutHandler)
r.HandleFunc("/books/{id:[0-9a-fA-F]+}", downloadHandler)
r.HandleFunc("/settings/", settingsHandler)
h := http.FileServer(http.Dir(IMG_PATH)) h := http.FileServer(http.Dir(IMG_PATH))
http.Handle("/img/", http.StripPrefix("/img/", h)) r.Handle("/img/{img}", http.StripPrefix("/img/", h))
h = http.FileServer(http.Dir(COVER_PATH)) h = http.FileServer(http.Dir(COVER_PATH))
http.Handle("/cover/", http.StripPrefix("/cover/", h)) r.Handle("/cover/{c}/{img}", http.StripPrefix("/cover/", h))
h = http.FileServer(http.Dir(CSS_PATH)) h = http.FileServer(http.Dir(CSS_PATH))
http.Handle("/css/", http.StripPrefix("/css/", h)) r.Handle("/css/{css}", http.StripPrefix("/css/", h))
h = http.FileServer(http.Dir(JS_PATH)) h = http.FileServer(http.Dir(JS_PATH))
http.Handle("/js/", http.StripPrefix("/js/", h)) r.Handle("/js/{js}", http.StripPrefix("/js/", h))
http.HandleFunc("/", indexHandler) http.Handle("/", r)
panic(http.ListenAndServe(":"+PORT, nil)) panic(http.ListenAndServe(":"+PORT, nil))
} }