http.FileServer behaviour?

550 views
Skip to first unread message

Paul Lalonde

unread,
Sep 14, 2011, 1:35:45 PM9/14/11
to golang-nuts
I'm having some unexpected behaviour from mux.Handle/http.FileServer
interaction - I'm not sure if it's a bug, or if I'm mis-understanding.
I add the following FileServer:
http.Handle("/files/", http.FileServer(http.Dir("./file_store")))

I expect when I go to //host/files/ to get a list of the files in my
local subdirectory "file_store". Instead, this points to files in
"file_store/files"
Essentially the entire mux path is appended to the directory passed to
the FileServer. Is this correct behaviour? The composition is a
little surprising.

Paul

Andy Balholm

unread,
Sep 14, 2011, 1:52:23 PM9/14/11
to golan...@googlegroups.com
try 

http.Handle("/files/", http.StripPrefix("/files", http.FileServer(http.Dir("./file_store"))))

andrey mirtchovski

unread,
Sep 14, 2011, 1:53:12 PM9/14/11
to Paul Lalonde, golang-nuts
Paul, you need StripPrefix:

http.Handle("/files/", http.StripPrefix("/files",
http.FileServer(http.Dir("./file_store"))))

andrey

Paul Lalonde

unread,
Sep 14, 2011, 2:00:46 PM9/14/11
to golang-nuts
Clever. Thanks.

Paul
Reply all
Reply to author
Forward
0 new messages