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

[Feature Request]Static File serving #35

Closed
netsharec opened this issue Mar 31, 2016 · 6 comments
Closed

[Feature Request]Static File serving #35

netsharec opened this issue Mar 31, 2016 · 6 comments

Comments

@netsharec
Copy link

When I'm using chi for a project with swagger-ui, I feel it is not so convenient for serving static files. What about adding the static file serving feature like this:

func (mx *Mux) Static(path, root string) {
    fs := http.StripPrefix(path, http.FileServer(http.Dir(root)))
    mx.Get(path+"/*", func(w http.ResponseWriter, r *http.Request) {
        fs.ServeHTTP(w, r)
    })
}
@pkieltyka
Copy link
Member

@netsharec I see what you mean. I'll add this function later today.

@fiorix
Copy link
Contributor

fiorix commented Mar 31, 2016

Please allow it to take an http.FileSystem instead of directory so we can serve static files from memory. I often do that along with go-bindata.

@pkieltyka
Copy link
Member

@fiorix good call

@pkieltyka
Copy link
Member

Merged in #36 - see new mux.FileServer(path string, root http.FileSystem) method.. example usage: https://github.com/pressly/chi/blob/master/mux_test.go#L734-L743

@philippgille
Copy link

@pkieltyka: Is it correct that this functionality doesn't exist anymore, but instead you have to follow this example?

@pkieltyka
Copy link
Member

yep, thats correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants