From b4e8eba34ca96d9298295eb9c01c1fc3d9036f3b Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 28 Oct 2019 20:03:55 +0100 Subject: New version --- server.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'server.go') diff --git a/server.go b/server.go index 0cb812e..d00bd6e 100644 --- a/server.go +++ b/server.go @@ -39,8 +39,8 @@ func encodeURL( urlStr string ) string { return urlStr } func normaliseName( name string ) string { - if len(name) > 27 { - name = name[:25] + "..." + if len(name) > 22 { + name = name[:20] + "..." } return name } @@ -58,7 +58,7 @@ func normaliseSize( size int64) string { if unit > 0 { return fmt.Sprintf("%.2f%cio", nb, unitStr[unit]); } - return fmt.Sprintf("%d", size); + return fmt.Sprintf("%do", size); } func getPath( r *http.Request ) string { if r.URL.Path == "/" { @@ -129,9 +129,9 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) { } for _, file := range fileInfo { if file.IsDir() { - cols = append(cols, Entry{normaliseName(file.Name()), initPath + file.Name(), 0, ""}) + cols = append(cols, Entry{file.Name(), initPath + file.Name(), 0, ""}) } else { - files = append(files, Entry{normaliseName(file.Name()), initPath + file.Name(), file.Size(), normaliseSize(file.Size())}) + files = append(files, Entry{file.Name(), initPath + file.Name(), file.Size(), normaliseSize(file.Size())}) } } type Collection struct { @@ -139,7 +139,9 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) { ListCols []Entry ListFiles []Entry } - tmpl.Execute(w, Collection{ filename, cols, files}) + name := "davy - " + filename + err = tmpl.Execute(w, Collection{ name, cols, files}) + fmt.Println(err) case stat.Mode().IsRegular(): if !headOnly { @@ -419,6 +421,7 @@ func main() { fmap := template.FuncMap{ "formatURL": encodeURL, "formatSize": normaliseSize, + "formatName": normaliseName, } tmpl = template.Must(template.New("dir.html").Funcs(fmap).ParseFiles("dir.html")) tmplXML = template.Must(template.New("xml.tmpl").Funcs(fmap).ParseFiles("xml.tmpl")) -- cgit v1.2.3