diff options
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -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")) |