FAQ
I'm very happy with the way that FileSystem provides safety, scope, range
support, etc for serving files off the file system. The only thing I don't
like is the index generation from dirList (I'd prefer to return a JSON
list, in this case)
( https://code.google.com/p/go/source/browse/src/pkg/net/http/fs.go#63 ).
  What's the best way to change the format of the generated index?

In trying not to suddenly have two problems, I was looking at just
modifying the returned text with a Handler, but that appears to require me
to intercept the writer since dirList writes directly to the
ResponseWriter. How to do this easily (and in a way that isn't tied
directly to dirList impl) isn't obvious to me, so suggestions are
appreciated.

I had a brain fart about adding an index generation method to FileSystem,
to allow for generic handling of files besides "index.html", templates
(like Apache), etc, but I couldn't come up with a solution that didn't seem
simpler than what already exists.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jeff R. Allen at Aug 21, 2013 at 1:04 pm
    This behaviour of the HTTP server is not modifiable from outside the
    net/http package.

    It seems to me you have two choices:

      a. hack the standard library
      b. extract func FileServer(root FileSystem) and everything it depends on
    (serveHttp, dirList, etc) from net/http/fs.go into your own package,
    customize it, and then tell the HTTP server to use it like this:

    import (
    "net/http"
    "your/own/fileserver"
    )

    func main() {
    ...
         root := "/var/www/htdocs"
         http.Handle("/", fileserver.FileServer(root))
    }

    Yanking stuff from the standard library and modifying it is less than
    ideal, but still fits into the Go way of doing things, because it keeps the
    standard library unencumbered by 1000 different customization
    "opportunities", but the system (and the license!) does not stand in your
    way of getting what you want done if you really need to do it.

    It you get stuck trying to extract the FileServer into a stand-alone
    package, I can try to do an example of it for you. Just ask.

       -jeff

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 21, '13 at 1:53a
activeAug 21, '13 at 1:04p
posts2
users2
websitegolang.org

2 users in discussion

Jeff R. Allen: 1 post Matt Reynolds: 1 post

People

Translate

site design / logo © 2022 Grokbase