From d0769b2cb3176360ee0e0a50baaeeda45380025a Mon Sep 17 00:00:00 2001 From: "Timofey.Kovalev" Date: Mon, 24 Sep 2018 12:59:41 +0300 Subject: [PATCH] commit --- handler.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/handler.go b/handler.go index d188c9e..8347350 100644 --- a/handler.go +++ b/handler.go @@ -100,7 +100,12 @@ func dirList(w http.ResponseWriter, r *http.Request, f http.File, name string) { renderError(w, "Error reading directory", http.StatusInternalServerError) return } - sort.Slice(dirs, func(i, j int) bool { return dirs[i].Name() < dirs[j].Name() }) + sort.Slice(dirs, func(i, j int) bool { + if dirs[i].IsDir() && !dirs[j].IsDir() { + return true + } + return dirs[i].Name() < dirs[j].Name() + }) w.Header().Set("Content-Type", "text/html; charset=utf-8") @@ -111,8 +116,9 @@ func dirList(w http.ResponseWriter, r *http.Request, f http.File, name string) { } data := &Data{ - Title: name, - Files: make([]*File, 0, len(dirs)), + Title: name, + IsRoot: name == "/", + Files: make([]*File, 0, len(dirs)), } for _, d := range dirs {