Cannot serve static files in a Go Gorilla server -
i playing small toy server learn go web programming.
my project directory structure has following public
directory:
public\ | style.css
the permissions on public
, style.css
r-x
, r--
everyone.
in main.go
, have following lines:
router := mux.newrouter() router.handle("/static/", http.stripprefix("/static/", http.fileserver(http.dir("public")))) log.fatal(http.listenandserve(":3001", router))
every time call http://localhost:3001/static/style.css
server returns 404.
i have tried combinations of leading , trailing slashes in paths, none make difference.
i running go v1.5.3 on ubuntu 15.10 (x64).
here's example of how can serve requests file in /static/
folder called public
.
router := mux.newrouter() //router.handle("/static/", http.stripprefix("/static/", http.fileserver(http.dir("public")))) router.pathprefix("/static/").handler(http.stripprefix("/static/", http.fileserver(http.dir("public/")))) log.fatal(http.listenandserve(":3001", router))
Comments
Post a Comment