browse: Sort directory contents by name

This commit is contained in:
Tom Adams 2015-06-18 22:39:49 -04:00
parent 6b27d4ce11
commit dda9a68499

View file

@ -9,6 +9,7 @@ import (
"net/url"
"os"
"path"
"sort"
"strings"
"time"
@ -65,6 +66,12 @@ func (fi FileInfo) HumanModTime(format string) string {
return fi.ModTime.Format(format)
}
type fileInfoByName []FileInfo
func (fi fileInfoByName) Len() int { return len(fi) }
func (fi fileInfoByName) Swap(i, j int) { fi[i], fi[j] = fi[j], fi[i] }
func (fi fileInfoByName) Less(i, j int) bool { return fi[i].Name < fi[j].Name }
var IndexPages = []string{
"index.html",
"index.htm",
@ -149,6 +156,8 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
continue
}
sort.Sort(fileInfoByName(fileinfos))
// Determine if user can browse up another folder
var canGoUp bool
curPath := strings.TrimSuffix(r.URL.Path, "/")