From 50eaa518f512a65097c47489890f9de7347f13c9 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Wed, 15 Jan 2020 13:44:48 +0100 Subject: [PATCH] Remove global vars --- handlers/login.go | 22 ------------------- main.go | 3 --- renderer/renderer.go | 52 -------------------------------------------- 3 files changed, 77 deletions(-) diff --git a/handlers/login.go b/handlers/login.go index fa83840d..bf80e488 100644 --- a/handlers/login.go +++ b/handlers/login.go @@ -19,28 +19,6 @@ type UserToken struct { UserID string } -var ( -// REMOVE -// signingKey = []byte(config.Config.Keys.JWTSigningKey) -// store = sessions.NewCookieStore([]byte(config.Config.Keys.CookieStoreKey)) - -// jwtCookie = jwtmiddleware.New(jwtmiddleware.Options{ -// ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) { -// return signingKey, nil -// }, -// SigningMethod: jwt.SigningMethodHS256, -// Extractor: fromCookie, -// ErrorHandler: onError, -// }) - -// jwtHeader = jwtmiddleware.New(jwtmiddleware.Options{ -// ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) { -// return signingKey, nil -// }, -// SigningMethod: jwt.SigningMethodHS256, -// }) -) - func DefaultLogoutHandler(store *sessions.CookieStore) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { session, err := store.Get(r, "login-session") diff --git a/main.go b/main.go index bec79410..b0f5cf9a 100644 --- a/main.go +++ b/main.go @@ -66,9 +66,6 @@ func main() { wait = false } - // REMOVE - // orm.Use(db) - if conf.Orm.AutoMigrate { log.Print("Automigrating...") db.AutoMigrate() diff --git a/renderer/renderer.go b/renderer/renderer.go index a8fc63cf..aeec7f4f 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -48,11 +48,6 @@ type JsonResponse struct { } var ( - // REMOVE - // store = sessions.NewCookieStore([]byte(config.Config.Keys.CookieStoreKey)) - // currRenderer Renderer - // Render map[string]func(http.ResponseWriter, *http.Request, *sessions.CookieStore, interface{}, ...url.Values) - contentTypeToFormat = map[string]string{ "application/x-www-form-urlencoded": "html", "text/html; charset=utf-8": "html", @@ -62,48 +57,6 @@ var ( } ) -func init() { - //REMOVE - // htmlRenderer, err := NewHTMLRenderer("templates/") - // if err != nil { - // panic(err) - // } - - // jsonRenderer, err := NewJSONRenderer() - // if err != nil { - // panic(err) - // } - - // csvRenderer, err := NewCSVRenderer() - // if err != nil { - // panic(err) - // } - - // pdfRenderer, err := NewPDFRenderer() - // if err != nil { - // panic(err) - // } - - // Render = make(map[string]func(http.ResponseWriter, *http.Request, *sessions.CookieStore, interface{}, ...url.Values)) - - // Render["html"] = func(w http.ResponseWriter, r *http.Request, store *sessions.CookieStore, data interface{}, options ...url.Values) { - // htmlRenderer.Render(w, r, store, data, options...) - // } - - // Render["json"] = func(w http.ResponseWriter, r *http.Request, store *sessions.CookieStore, data interface{}, options ...url.Values) { - // jsonRenderer.Render(w, r, store, data, options...) - // } - - // Render["csv"] = func(w http.ResponseWriter, r *http.Request, store *sessions.CookieStore, data interface{}, options ...url.Values) { - // csvRenderer.Render(w, r, data, options...) - // } - - // Render["pdf"] = func(w http.ResponseWriter, r *http.Request, store *sessions.CookieStore, data interface{}, options ...url.Values) { - // pdfRenderer.Render(w, r, data, options...) - // } - -} - func Query(values ...string) template.URL { return query(values...) } @@ -227,11 +180,6 @@ func NewHTMLRenderer(templatePath string) (*HTMLRenderer, error) { return r, nil } -// REMOVE -// func Use(r Renderer) { -// currRenderer = r -// } - func (rend *HTMLRenderer) writeError(w http.ResponseWriter, r *http.Request, data interface{}) { var t *template.Template