From 8120e57850b3f92c8680d1184425247e634e2eb0 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 18 Sep 2015 08:52:12 +0100 Subject: [PATCH] add user defined variables into browse template --- middleware/browse/browse.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/middleware/browse/browse.go b/middleware/browse/browse.go index c4ff6ef5..dbbe25fc 100644 --- a/middleware/browse/browse.go +++ b/middleware/browse/browse.go @@ -32,6 +32,7 @@ type Browse struct { // Config is a configuration for browsing in a particular path. type Config struct { PathScope string + Variables interface{} Template *template.Template } @@ -55,6 +56,9 @@ type Listing struct { // And which order Order string + // User defined costum variables + User interface{} + middleware.Context } @@ -143,7 +147,7 @@ var IndexPages = []string{ "default.txt", } -func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string, ignoreIndexes bool) (Listing, error) { +func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string, ignoreIndexes bool, vars interface{}) (Listing, error) { var fileinfos []FileInfo var urlPath = r.URL.Path for _, f := range files { @@ -184,6 +188,7 @@ func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root s Req: r, URL: r.URL, }, + User: vars, }, nil } @@ -237,7 +242,7 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { } } // Assemble listing of directory contents - listing, err := directoryListing(files, r, canGoUp, b.Root, b.IgnoreIndexes) + listing, err := directoryListing(files, r, canGoUp, b.Root, b.IgnoreIndexes, bc.Variables) if err != nil { // directory isn't browsable continue }