From f494776931b71f83fdfdd4e68e850529c4b2614f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 20 Oct 2021 22:37:19 +0800 Subject: Use a variable but a function for IsProd because of a slight performance increment (#17368) --- routers/common/middleware.go | 2 +- routers/install/routes.go | 4 ++-- routers/web/base.go | 4 ++-- routers/web/web.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'routers') diff --git a/routers/common/middleware.go b/routers/common/middleware.go index 1d96522dd9..7c5c72f5cc 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -62,7 +62,7 @@ func Middlewares() []func(http.Handler) http.Handler { if err := recover(); err != nil { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) log.Error("%v", combinedErr) - if setting.IsProd() { + if setting.IsProd { http.Error(resp, http.StatusText(500), 500) } else { http.Error(resp, combinedErr, 500) diff --git a/routers/install/routes.go b/routers/install/routes.go index e9aca85d8e..ad0003a9e8 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -40,7 +40,7 @@ func installRecovery() func(next http.Handler) http.Handler { if err := recover(); err != nil { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) log.Error(combinedErr) - if setting.IsProd() { + if setting.IsProd { http.Error(w, http.StatusText(500), 500) } else { http.Error(w, combinedErr, 500) @@ -63,7 +63,7 @@ func installRecovery() func(next http.Handler) http.Handler { w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions) - if !setting.IsProd() { + if !setting.IsProd { store["ErrorMsg"] = combinedErr } err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store)) diff --git a/routers/web/base.go b/routers/web/base.go index f50c5229b1..16d3192da2 100644 --- a/routers/web/base.go +++ b/routers/web/base.go @@ -131,7 +131,7 @@ func Recovery() func(next http.Handler) http.Handler { sessionStore := session.GetSession(req) if sessionStore == nil { - if setting.IsProd() { + if setting.IsProd { http.Error(w, http.StatusText(500), 500) } else { http.Error(w, combinedErr, 500) @@ -164,7 +164,7 @@ func Recovery() func(next http.Handler) http.Handler { w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions) - if !setting.IsProd() { + if !setting.IsProd { store["ErrorMsg"] = combinedErr } err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store)) diff --git a/routers/web/web.go b/routers/web/web.go index caec067671..88565d6d85 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -477,7 +477,7 @@ func RegisterRoutes(m *web.Route) { m.Post("/action/{action}", user.Action) }, reqSignIn) - if !setting.IsProd() { + if !setting.IsProd { m.Get("/template/*", dev.TemplatePreview) } -- cgit v1.2.3