From 89d7d71cc5b443dc392ca9aa4368362467a7d70a Mon Sep 17 00:00:00 2001 From: James Mills Date: Fri, 27 Mar 2020 18:16:23 +1000 Subject: Display video size --- app/app.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 8c5c79f..bb13895 100644 --- a/app/app.go +++ b/app/app.go @@ -15,6 +15,7 @@ import ( "strings" rice "github.com/GeertJohan/go.rice" + "github.com/dustin/go-humanize" "github.com/fsnotify/fsnotify" "github.com/gorilla/handlers" "github.com/gorilla/mux" @@ -74,17 +75,21 @@ func NewApp(cfg *Config) (*App, error) { a.Templates = newTemplateStore("base") - indexTemplate := template.New("index") + templateFuncs := map[string]interface{}{ + "bytes": func(size int64) string { return humanize.Bytes(uint64(size)) }, + } + + indexTemplate := template.New("index").Funcs(templateFuncs) template.Must(indexTemplate.Parse(box.MustString("index.html"))) template.Must(indexTemplate.Parse(box.MustString("base.html"))) a.Templates.Add("index", indexTemplate) - uploadTemplate := template.New("upload") + uploadTemplate := template.New("upload").Funcs(templateFuncs) template.Must(uploadTemplate.Parse(box.MustString("upload.html"))) template.Must(uploadTemplate.Parse(box.MustString("base.html"))) a.Templates.Add("upload", uploadTemplate) - importTemplate := template.New("import") + importTemplate := template.New("import").Funcs(templateFuncs) template.Must(importTemplate.Parse(box.MustString("import.html"))) template.Must(importTemplate.Parse(box.MustString("base.html"))) a.Templates.Add("import", importTemplate) -- cgit v1.2.3