summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-20 19:39:43 +0100
committerache <ache@ache.one>2019-02-20 19:39:43 +0100
commit35bc85937d4ca09d2b9752086b25ef38cb6e82d9 (patch)
treefab7304042b825da96174668b1e6b5d42a49b4fd /server.go
parentUse table to show information (diff)
Size normalisation
Diffstat (limited to 'server.go')
-rw-r--r--server.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/server.go b/server.go
index b871654..3b5c732 100644
--- a/server.go
+++ b/server.go
@@ -21,6 +21,21 @@ func normaliseName( name string ) string {
return name
}
+func normaliseSize( size int64) string {
+ unit := 0
+ nb := float64(size)
+ for nb > 1023. {
+ unit++
+ nb /= 1024.
+ }
+
+ unitStr := " KMGTPEZY"
+
+ if unit > 0 {
+ return fmt.Sprintf("%.2f%cio", nb, unitStr[unit]);
+ }
+ return fmt.Sprintf("%d", size);
+}
func getPath( r *http.Request ) string {
if r.URL.Path == "/" {
return "."
@@ -52,6 +67,7 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
Name string
Path string
Size int64
+ SizePrint string
}
var files []Entry
@@ -82,16 +98,16 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
initPath := r.URL.Path;
- cols = append(cols, Entry{".", initPath, 0})
+ cols = append(cols, Entry{".", initPath, 0, ""})
if initPath != "/" {
- cols = append(cols, Entry{"..", path.Dir(initPath), 0})
+ cols = append(cols, Entry{"..", path.Dir(initPath), 0, ""})
initPath += "/"
}
for _, file := range fileInfo {
if file.IsDir() {
- cols = append(cols, Entry{normaliseName(file.Name()), initPath + file.Name(), 0})
+ cols = append(cols, Entry{normaliseName(file.Name()), initPath + file.Name(), 0, ""})
} else {
- files = append(files, Entry{normaliseName(file.Name()), initPath + file.Name(), file.Size()})
+ files = append(files, Entry{normaliseName(file.Name()), initPath + file.Name(), file.Size(), normaliseSize(file.Size())})
}
}
type Collection struct {