Use config paths to serve files
This commit is contained in:
parent
15bebb7677
commit
34b48f411c
2 changed files with 11 additions and 9 deletions
|
@ -14,6 +14,9 @@ const (
|
|||
BOOKS_PATH = "books/"
|
||||
COVER_PATH = "cover/"
|
||||
NEW_PATH = "new/"
|
||||
CSS_PATH = "css/"
|
||||
JS_PATH = "js/"
|
||||
IMG_PATH = "img/"
|
||||
RESIZE_CMD = "/usr/bin/convert -resize 300 -quality 60 "
|
||||
RESIZE_THUMB_CMD = "/usr/bin/convert -resize 60 -quality 60 "
|
||||
)
|
||||
|
|
17
trantor.go
17
trantor.go
|
@ -66,11 +66,6 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
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 {
|
||||
S Status
|
||||
Books []Book
|
||||
|
@ -144,10 +139,14 @@ func main() {
|
|||
http.HandleFunc("/about/", aboutHandler)
|
||||
http.HandleFunc("/books/", downloadHandler)
|
||||
http.HandleFunc("/settings/", settingsHandler)
|
||||
fileHandler("/img/")
|
||||
fileHandler("/cover/")
|
||||
fileHandler("/css/")
|
||||
fileHandler("/js/")
|
||||
h := http.FileServer(http.Dir(IMG_PATH))
|
||||
http.Handle("/img/", http.StripPrefix("/img/", h))
|
||||
h = http.FileServer(http.Dir(COVER_PATH))
|
||||
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)
|
||||
panic(http.ListenAndServe(":"+PORT, nil))
|
||||
}
|
||||
|
|
Reference in a new issue