diff options
-rw-r--r-- | cmd/serv.go | 4 | ||||
-rw-r--r-- | models/models.go | 4 | ||||
-rw-r--r-- | modules/auth/sso/sspi_windows.go | 2 | ||||
-rw-r--r-- | modules/httpcache/httpcache.go | 2 | ||||
-rw-r--r-- | modules/setting/setting.go | 6 | ||||
-rw-r--r-- | routers/init.go | 2 | ||||
-rw-r--r-- | routers/routes/recovery.go | 11 |
7 files changed, 17 insertions, 14 deletions
diff --git a/cmd/serv.go b/cmd/serv.go index fb1e581134..1e66cb5111 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -58,7 +58,7 @@ func setup(logPath string, debug bool) { } setting.NewContext() if debug { - setting.ProdMode = false + setting.RunMode = "dev" } } @@ -76,7 +76,7 @@ func fail(userMessage, logMessage string, args ...interface{}) { fmt.Fprintln(os.Stderr, "Gitea:", userMessage) if len(logMessage) > 0 { - if !setting.ProdMode { + if !setting.IsProd() { fmt.Fprintf(os.Stderr, logMessage+"\n", args...) } } diff --git a/models/models.go b/models/models.go index f12a4e8b30..2ace1ea6dd 100644 --- a/models/models.go +++ b/models/models.go @@ -175,8 +175,8 @@ func NewTestEngine() (err error) { } x.SetMapper(names.GonicMapper{}) - x.SetLogger(NewXORMLogger(!setting.ProdMode)) - x.ShowSQL(!setting.ProdMode) + x.SetLogger(NewXORMLogger(!setting.IsProd())) + x.ShowSQL(!setting.IsProd()) return x.StoreEngine("InnoDB").Sync2(tables...) } diff --git a/modules/auth/sso/sspi_windows.go b/modules/auth/sso/sspi_windows.go index 46309c27f7..448336c07b 100644 --- a/modules/auth/sso/sspi_windows.go +++ b/modules/auth/sso/sspi_windows.go @@ -56,7 +56,7 @@ func (s *SSPI) Init() error { Funcs: templates.NewFuncMap(), Asset: templates.GetAsset, AssetNames: templates.GetAssetNames, - IsDevelopment: setting.RunMode != "prod", + IsDevelopment: !setting.IsProd(), }) return nil } diff --git a/modules/httpcache/httpcache.go b/modules/httpcache/httpcache.go index c4134f8e17..cf35cef129 100644 --- a/modules/httpcache/httpcache.go +++ b/modules/httpcache/httpcache.go @@ -17,7 +17,7 @@ import ( // GetCacheControl returns a suitable "Cache-Control" header value func GetCacheControl() string { - if setting.RunMode == "dev" { + if !setting.IsProd() { return "no-store" } return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 8ab4508ce5..c162c751c1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -376,7 +376,6 @@ var ( CustomConf string PIDFile = "/run/gitea.pid" WritePIDFile bool - ProdMode bool RunMode string RunUser string IsWindows bool @@ -388,6 +387,11 @@ var ( UILocation = time.Local ) +// IsProd if it's a production mode +func IsProd() bool { + return strings.EqualFold(RunMode, "prod") +} + func getAppPath() (string, error) { var appPath string var err error diff --git a/routers/init.go b/routers/init.go index ff2ddcc0b7..79e2f9130a 100644 --- a/routers/init.go +++ b/routers/init.go @@ -50,7 +50,7 @@ func checkRunMode() { default: macaron.Env = macaron.PROD macaron.ColorLog = false - setting.ProdMode = true + git.Debug = false } log.Info("Run Mode: %s", strings.Title(macaron.Env)) } diff --git a/routers/routes/recovery.go b/routers/routes/recovery.go index 7f33fee0f3..cfe1a4114c 100644 --- a/routers/routes/recovery.go +++ b/routers/routes/recovery.go @@ -29,7 +29,6 @@ func (d *dataStore) GetData() map[string]interface{} { // Although similar to macaron.Recovery() the main difference is that this error will be created // with the gitea 500 page. func Recovery() func(next http.Handler) http.Handler { - var isDevelopment = setting.RunMode != "prod" return func(next http.Handler) http.Handler { rnd := render.New(render.Options{ Extensions: []string{".tmpl"}, @@ -37,7 +36,7 @@ func Recovery() func(next http.Handler) http.Handler { Funcs: templates.NewFuncMap(), Asset: templates.GetAsset, AssetNames: templates.GetAssetNames, - IsDevelopment: isDevelopment, + IsDevelopment: !setting.IsProd(), }) return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { @@ -50,10 +49,10 @@ func Recovery() 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 isDevelopment { - http.Error(w, combinedErr, 500) - } else { + if setting.IsProd() { http.Error(w, http.StatusText(500), 500) + } else { + http.Error(w, combinedErr, 500) } } }() @@ -94,7 +93,7 @@ func Recovery() func(next http.Handler) http.Handler { w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`) - if setting.RunMode != "prod" { + if !setting.IsProd() { store.Data["ErrorMsg"] = combinedErr } err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data)) |