Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2ba887871e
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (28 sloc) 0.551 kb
package main
import (
"net/http"
"strings"
)
type StaticFileHandler string
func (h StaticFileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if upath := r.URL.Path; !strings.HasPrefix(upath, "/") {
upath = "/" + upath
r.URL.Path = upath
}
f, err := http.Dir(h).Open(r.URL.Path)
if err != nil {
http.NotFound(w, r)
return
}
defer f.Close()
d, err1 := f.Stat()
if err1 != nil {
http.NotFound(w, r)
return
}
if d.IsDir() {
http.NotFound(w, r)
return
}
http.ServeContent(w, r, d.Name(), d.ModTime(), f)
}
Jump to Line
Something went wrong with that request. Please try again.