A tiny improvement to the context.ServeFile

Former-commit-id: e9eaa1f51c08ec74cbc17c7cd3f62d557faf23a0
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-10-01 19:02:55 +03:00
parent 38c6241055
commit 4ff0571785
2 changed files with 3 additions and 9 deletions

View File

@ -4,9 +4,8 @@ import (
"github.com/kataras/iris/_examples/structuring/handler-based/bootstrap"
)
// Configure registers the nessecary routes to the app.
// Configure registers the necessary routes to the app.
func Configure(b *bootstrap.Bootstrapper) {
// routes
b.Get("/", GetIndexHandler)
b.Get("/follower/{id:long}", GetFollowerHandler)
b.Get("/following/{id:long}", GetFollowingHandler)

View File

@ -2317,15 +2317,10 @@ func (ctx *context) ServeFile(filename string, gzipCompression bool) error {
defer f.Close()
fi, _ := f.Stat()
if fi.IsDir() {
filename = path.Join(filename, "index.html")
f, err = os.Open(filename)
if err != nil {
return fmt.Errorf("%d", 404)
}
fi, _ = f.Stat()
return ctx.ServeFile(path.Join(filename, "index.html"), gzipCompression)
}
return ctx.ServeContent(f, fi.Name(), fi.ModTime(), gzipCompression)
return ctx.ServeContent(f, fi.Name(), fi.ModTime(), gzipCompression)
}
// SendFile sends file for force-download to the client