1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Refactor config package

- Parse configuration only once during startup time
- Store configuration values in a global variable
This commit is contained in:
Frédéric Guillot 2019-06-01 18:18:09 -07:00 committed by fguillot
parent 04d85b3c63
commit 228862fefa
28 changed files with 922 additions and 624 deletions

View file

@ -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
}