Skip to content

Commit 84b147c

Browse files
lunny6543zeripath
authored
Use IsProd instead of testing if it's equal. (#14336)
Co-authored-by: 6543 <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent 60a3297 commit 84b147c

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

cmd/serv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func setup(logPath string, debug bool) {
5858
}
5959
setting.NewContext()
6060
if debug {
61-
setting.ProdMode = false
61+
setting.RunMode = "dev"
6262
}
6363
}
6464

@@ -76,7 +76,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
7676
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
7777

7878
if len(logMessage) > 0 {
79-
if !setting.ProdMode {
79+
if !setting.IsProd() {
8080
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
8181
}
8282
}

models/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func NewTestEngine() (err error) {
175175
}
176176

177177
x.SetMapper(names.GonicMapper{})
178-
x.SetLogger(NewXORMLogger(!setting.ProdMode))
179-
x.ShowSQL(!setting.ProdMode)
178+
x.SetLogger(NewXORMLogger(!setting.IsProd()))
179+
x.ShowSQL(!setting.IsProd())
180180
return x.StoreEngine("InnoDB").Sync2(tables...)
181181
}
182182

modules/auth/sso/sspi_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *SSPI) Init() error {
5656
Funcs: templates.NewFuncMap(),
5757
Asset: templates.GetAsset,
5858
AssetNames: templates.GetAssetNames,
59-
IsDevelopment: setting.RunMode != "prod",
59+
IsDevelopment: !setting.IsProd(),
6060
})
6161
return nil
6262
}

modules/httpcache/httpcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// GetCacheControl returns a suitable "Cache-Control" header value
1919
func GetCacheControl() string {
20-
if setting.RunMode == "dev" {
20+
if !setting.IsProd() {
2121
return "no-store"
2222
}
2323
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)

modules/setting/setting.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ var (
376376
CustomConf string
377377
PIDFile = "/run/gitea.pid"
378378
WritePIDFile bool
379-
ProdMode bool
380379
RunMode string
381380
RunUser string
382381
IsWindows bool
@@ -388,6 +387,11 @@ var (
388387
UILocation = time.Local
389388
)
390389

390+
// IsProd if it's a production mode
391+
func IsProd() bool {
392+
return strings.EqualFold(RunMode, "prod")
393+
}
394+
391395
func getAppPath() (string, error) {
392396
var appPath string
393397
var err error

routers/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func checkRunMode() {
5050
default:
5151
macaron.Env = macaron.PROD
5252
macaron.ColorLog = false
53-
setting.ProdMode = true
53+
git.Debug = false
5454
}
5555
log.Info("Run Mode: %s", strings.Title(macaron.Env))
5656
}

routers/routes/recovery.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ func (d *dataStore) GetData() map[string]interface{} {
2929
// Although similar to macaron.Recovery() the main difference is that this error will be created
3030
// with the gitea 500 page.
3131
func Recovery() func(next http.Handler) http.Handler {
32-
var isDevelopment = setting.RunMode != "prod"
3332
return func(next http.Handler) http.Handler {
3433
rnd := render.New(render.Options{
3534
Extensions: []string{".tmpl"},
3635
Directory: "templates",
3736
Funcs: templates.NewFuncMap(),
3837
Asset: templates.GetAsset,
3938
AssetNames: templates.GetAssetNames,
40-
IsDevelopment: isDevelopment,
39+
IsDevelopment: !setting.IsProd(),
4140
})
4241

4342
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
@@ -50,10 +49,10 @@ func Recovery() func(next http.Handler) http.Handler {
5049
if err := recover(); err != nil {
5150
combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
5251
log.Error(combinedErr)
53-
if isDevelopment {
54-
http.Error(w, combinedErr, 500)
55-
} else {
52+
if setting.IsProd() {
5653
http.Error(w, http.StatusText(500), 500)
54+
} else {
55+
http.Error(w, combinedErr, 500)
5756
}
5857
}
5958
}()
@@ -94,7 +93,7 @@ func Recovery() func(next http.Handler) http.Handler {
9493

9594
w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
9695

97-
if setting.RunMode != "prod" {
96+
if !setting.IsProd() {
9897
store.Data["ErrorMsg"] = combinedErr
9998
}
10099
err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data))

0 commit comments

Comments
 (0)