From 4ff05717856aef36c90677eec0f290ab31d15995 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sun, 1 Oct 2017 19:02:55 +0300 Subject: [PATCH] A tiny improvement to the `context.ServeFile` Former-commit-id: e9eaa1f51c08ec74cbc17c7cd3f62d557faf23a0 --- _examples/structuring/handler-based/routes/routes.go | 3 +-- context/context.go | 9 ++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/_examples/structuring/handler-based/routes/routes.go b/_examples/structuring/handler-based/routes/routes.go index 555acd12..7d6c51c3 100644 --- a/_examples/structuring/handler-based/routes/routes.go +++ b/_examples/structuring/handler-based/routes/routes.go @@ -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) diff --git a/context/context.go b/context/context.go index 2bfa84c5..e1992bb3 100644 --- a/context/context.go +++ b/context/context.go @@ -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