Use config paths to serve files

This commit is contained in:
Las Zenow 2012-10-28 19:21:42 +01:00
parent 15bebb7677
commit 34b48f411c
2 changed files with 11 additions and 9 deletions

View file

@ -14,6 +14,9 @@ const (
BOOKS_PATH = "books/" BOOKS_PATH = "books/"
COVER_PATH = "cover/" COVER_PATH = "cover/"
NEW_PATH = "new/" NEW_PATH = "new/"
CSS_PATH = "css/"
JS_PATH = "js/"
IMG_PATH = "img/"
RESIZE_CMD = "/usr/bin/convert -resize 300 -quality 60 " RESIZE_CMD = "/usr/bin/convert -resize 300 -quality 60 "
RESIZE_THUMB_CMD = "/usr/bin/convert -resize 60 -quality 60 " RESIZE_THUMB_CMD = "/usr/bin/convert -resize 60 -quality 60 "
) )

View file

@ -66,11 +66,6 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, file) http.ServeFile(w, r, file)
} }
func fileHandler(path string) {
h := http.FileServer(http.Dir(path[1:]))
http.Handle(path, http.StripPrefix(path, h))
}
type indexData struct { type indexData struct {
S Status S Status
Books []Book Books []Book
@ -144,10 +139,14 @@ func main() {
http.HandleFunc("/about/", aboutHandler) http.HandleFunc("/about/", aboutHandler)
http.HandleFunc("/books/", downloadHandler) http.HandleFunc("/books/", downloadHandler)
http.HandleFunc("/settings/", settingsHandler) http.HandleFunc("/settings/", settingsHandler)
fileHandler("/img/") h := http.FileServer(http.Dir(IMG_PATH))
fileHandler("/cover/") http.Handle("/img/", http.StripPrefix("/img/", h))
fileHandler("/css/") h = http.FileServer(http.Dir(COVER_PATH))
fileHandler("/js/") http.Handle("/cover/", http.StripPrefix("/cover/", h))
h = http.FileServer(http.Dir(CSS_PATH))
http.Handle("/css/", http.StripPrefix("/css/", h))
h = http.FileServer(http.Dir(JS_PATH))
http.Handle("/js/", http.StripPrefix("/js/", h))
http.HandleFunc("/", indexHandler) http.HandleFunc("/", indexHandler)
panic(http.ListenAndServe(":"+PORT, nil)) panic(http.ListenAndServe(":"+PORT, nil))
} }