Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: mention StripPrefix in FileServer section #3530

Closed
gopherbot opened this issue Apr 15, 2012 · 6 comments
Closed

net/http: mention StripPrefix in FileServer section #3530

gopherbot opened this issue Apr 15, 2012 · 6 comments

Comments

@gopherbot
Copy link

by sedaAK:

I wanted to put my /static subdirectory up as http://mysite/static, so I did the
following:

http.Handle("/static/",
http.FileServer(http.Dir("/projects/static")))

However browsing to http://mysite/static resolving to /projects/static/static, which
didn't exist.

So the code that ended up working is:
http.Handle("/static/", http.FileServer(http.Dir("/projects/")))

That looks totally wrong to me and causes a major limitation.  I want to say, mount this
directory there, not take this url path, then add it on to the filepath I give.   What
if I wanted the urlpath to not match the filepath?   If I want to call
http://mysite/somefiles and map it to /projects/someonesfolder  then I would be out of
luck and have to use some other muxer.
@gopherbot
Copy link
Author

Comment 1 by sedaAK:

kevlar directed me to http.StripPrefix to resolve my issue.  I still think this is
counter-intuitive.  I can't conceive of a situation where the prefix being passed to the
filesystem helps a coders understanding.

@minux
Copy link
Member

minux commented Apr 15, 2012

Comment 2:

We can't change the behavior of http.FileServer now (it's frozen by Go 1 release), but
we can
mention StripPrefix in the documentation of http.Server.
http://golang.org/cl/6032052

Labels changed: added priority-later, documentation, removed priority-triage.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 3 by sedaAK:

thanks :-), if it mentioned that in the documentation it would have saved me the agony. 
The docs only give the example of the simplest case, mounting the file system at "/", so
either an example using StripPrefix when using /otherfolder or some other mention.

@rsc
Copy link
Contributor

rsc commented Apr 17, 2012

Comment 4:

It seems great to add an example for FileServer that uses StripPrefix during the
registration.

@minux
Copy link
Member

minux commented Apr 19, 2012

Comment 5:

This issue was closed by revision acb5505.

Status changed to Fixed.

@minux
Copy link
Member

minux commented Apr 25, 2012

Comment 6:

This issue was closed by revision 2fce9be95aab.

minux added a commit that referenced this issue May 11, 2015
…StripPrefix

««« backport 362b760ecfc7
net/http: add example for FileServer to mention StripPrefix
        Fixes #3530.

R=golang-dev, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6032052
»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants