Skip to content

Instantly share code, notes, and snippets.

@landongn
Created September 11, 2013 03:21
Show Gist options
  • Save landongn/6518972 to your computer and use it in GitHub Desktop.
Save landongn/6518972 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/emicklei/go-restful"
"net/http"
"path"
)
var rootdir = "/Users/landon/Projects/web/Raddit/release"
func main() {
ws := new(restful.WebService)
ws.Route(ws.GET("/static/{resource}").To(staticFromPathParam))
ws.Route(ws.GET("/static").To(staticFromQueryParam))
restful.Add(ws)
println("[go-restful] serving files on http://0.0.0.0:8080/static from local ")
http.ListenAndServe(":8080", nil)
}
func staticFromPathParam(req *restful.Request, resp *restful.Response) {
http.ServeFile(
resp.ResponseWriter,
req.Request,
path.Join(rootdir, req.PathParameter("resource"))
)
}
func staticFromQueryParam(req *restful.Request, resp *restful.Response) {
http.ServeFile(
resp.ResponseWriter,
req.Request,
path.Join(rootdir, req.QueryParameter("resource"))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment