dbrain / soggy

An fast and simple express/sinatra like web framework.. thing.. for Go.
45 stars 1 forks source link

Static file serving #7

Closed dbrain closed 12 years ago

dbrain commented 12 years ago

As somebody from the past, I'd like to be able to serve static files to a user without writing my own io code, probably from a set directory, with some funkiness around what headers are sent back so the files can be cached.

dbrain commented 12 years ago

This is done, as middleware.

// Capture requests for /mountpoint/static and look for files in CWD/public
server.Use(soggy.NewStaticServerMiddleware("/static"))
// Change default static path
server.Config.SetStaticPath("notPublic")

If file is not found or a directory it will continue to the next middleware (hitting 404 handlers or your own route starting with /static).