Permalink
Browse files

Create custom http filesystem (#170)

  • Loading branch information...
kochman authored and garoller committed Oct 10, 2018
1 parent 421137f commit ea7775f80b440d1794c1ccdb4dc65735b0bbcd6c
Showing with 29 additions and 1 deletion.
  1. +1 −1 api/api.go
  2. +28 −0 api/filesystem.go
View
@@ -120,7 +120,7 @@ func New(cfg Config, ms shuttletracker.ModelService, msg shuttletracker.MessageS
// Static files
r.Get("/", IndexHandler)
r.Method("GET", "/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
r.Method("GET", "/static/*", http.StripPrefix("/static/", http.FileServer(staticFileSystem{http.Dir("static/")})))
// iTRAK data feed endpoint
r.Get("/datafeed", api.DataFeedHandler)
View
@@ -0,0 +1,28 @@
package api
import (
"net/http"
"os"
)
type staticFileSystem struct {
fs http.FileSystem
}
// Open will only return Files that are not directories.
func (sfs staticFileSystem) Open(path string) (http.File, error) {
f, err := sfs.fs.Open(path)
if err != nil {
return nil, err
}
s, err := f.Stat()
if err != nil {
return nil, err
}
if s.IsDir() {
return nil, os.ErrNotExist
}
return f, nil
}

0 comments on commit ea7775f

Please sign in to comment.