From 228862fefaa645026caa483ffe9993bf8c00b22e Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 1 Jun 2019 18:18:09 -0700 Subject: Refactor config package - Parse configuration only once during startup time - Store configuration values in a global variable --- template/functions.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'template/functions.go') diff --git a/template/functions.go b/template/functions.go index d99f237..0f5b180 100644 --- a/template/functions.go +++ b/template/functions.go @@ -7,8 +7,8 @@ package template // import "miniflux.app/template" import ( "encoding/base64" "fmt" - "math" "html/template" + "math" "net/mail" "strings" "time" @@ -20,12 +20,11 @@ import ( "miniflux.app/timezone" "miniflux.app/url" - "github.com/gorilla/mux" "github.com/PuerkitoBio/goquery" + "github.com/gorilla/mux" ) type funcMap struct { - cfg *config.Config router *mux.Router } @@ -37,13 +36,13 @@ func (f *funcMap) Map() template.FuncMap { "truncate": truncate, "isEmail": isEmail, "baseURL": func() string { - return f.cfg.BaseURL() + return config.Opts.BaseURL() }, "rootURL": func() string { - return f.cfg.RootURL() + return config.Opts.RootURL() }, "hasOAuth2Provider": func(provider string) bool { - return f.cfg.OAuth2Provider() == provider + return config.Opts.OAuth2Provider() == provider }, "route": func(name string, args ...interface{}) string { return route.Path(f.router, name, args...) @@ -52,10 +51,10 @@ func (f *funcMap) Map() template.FuncMap { return template.HTML(str) }, "proxyFilter": func(data string) string { - return imageProxyFilter(f.router, f.cfg, data) + return imageProxyFilter(f.router, data) }, "proxyURL": func(link string) string { - proxyImages := f.cfg.ProxyImages() + proxyImages := config.Opts.ProxyImages() if proxyImages == "all" || (proxyImages != "none" && !url.IsHTTPS(link)) { return proxify(f.router, link) @@ -92,10 +91,6 @@ func (f *funcMap) Map() template.FuncMap { } } -func newFuncMap(cfg *config.Config, router *mux.Router) *funcMap { - return &funcMap{cfg, router} -} - func dict(values ...interface{}) (map[string]interface{}, error) { if len(values)%2 != 0 { return nil, fmt.Errorf("dict expects an even number of arguments") @@ -178,8 +173,8 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { } } -func imageProxyFilter(router *mux.Router, cfg *config.Config, data string) string { - proxyImages := cfg.ProxyImages() +func imageProxyFilter(router *mux.Router, data string) string { + proxyImages := config.Opts.ProxyImages() if proxyImages == "none" { return data } -- cgit v1.2.3