summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-10-28 20:03:55 +0100
committerache <ache@ache.one>2019-10-28 20:03:55 +0100
commitb4e8eba34ca96d9298295eb9c01c1fc3d9036f3b (patch)
tree2d89cf0276ab80a2ac0fd43b957c203ff646ffc7 /server.go
parentNew interface (diff)
New version
Diffstat (limited to 'server.go')
-rw-r--r--server.go15
1 files changed, 9 insertions, 6 deletions
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"))