]> source.dussan.org Git - gitea.git/commitdiff
Use IsProd instead of testing if it's equal. (#14336)
authorLunny Xiao <xiaolunwen@gmail.com>
Thu, 14 Jan 2021 21:17:03 +0000 (05:17 +0800)
committerGitHub <noreply@github.com>
Thu, 14 Jan 2021 21:17:03 +0000 (23:17 +0200)
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: zeripath <art27@cantab.net>
cmd/serv.go
models/models.go
modules/auth/sso/sspi_windows.go
modules/httpcache/httpcache.go
modules/setting/setting.go
routers/init.go
routers/routes/recovery.go

index fb1e581134bce7548f4012756628ed4c836b0ac3..1e66cb511100064bb412cde420f04eb6b2419988 100644 (file)
@@ -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...)
                }
        }
index f12a4e8b304caaf9c2ab2786428df36ddfa6da41..2ace1ea6dd6a951d07ac102eaac152631f5c8092 100644 (file)
@@ -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...)
 }
 
index 46309c27f71a366d5fdb7fc62ee5481926888fc8..448336c07b309925d71c39a1a9d9ea40a811fd7d 100644 (file)
@@ -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
 }
index c4134f8e17b9773745dd9c34446063887e2a581f..cf35cef129b49ff54bb296db3a5a6276c2b79576 100644 (file)
@@ -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)
index 8ab4508ce53996b29dff6996fc8be38773d39b34..c162c751c11e409e82f76c67a597cab726c00274 100644 (file)
@@ -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
index ff2ddcc0b711c4c3805dd3e0834e58f73a753179..79e2f9130ab2a9b45b8399ea24056f5d88b26352 100644 (file)
@@ -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))
 }
index 7f33fee0f3353651875b3d321dbfcf6720d91bca..cfe1a4114cad6d3c2f5f952afc4f65edafec3201 100644 (file)
@@ -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))