mirror of https://github.com/go-gitea/gitea.git
Use IsProd instead of testing if it's equal. (#14336)
Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
60a3297a33
commit
84b147c7f0
|
@ -58,7 +58,7 @@ func setup(logPath string, debug bool) {
|
||||||
}
|
}
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
if debug {
|
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)
|
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
|
||||||
|
|
||||||
if len(logMessage) > 0 {
|
if len(logMessage) > 0 {
|
||||||
if !setting.ProdMode {
|
if !setting.IsProd() {
|
||||||
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
|
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,8 +175,8 @@ func NewTestEngine() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
x.SetMapper(names.GonicMapper{})
|
x.SetMapper(names.GonicMapper{})
|
||||||
x.SetLogger(NewXORMLogger(!setting.ProdMode))
|
x.SetLogger(NewXORMLogger(!setting.IsProd()))
|
||||||
x.ShowSQL(!setting.ProdMode)
|
x.ShowSQL(!setting.IsProd())
|
||||||
return x.StoreEngine("InnoDB").Sync2(tables...)
|
return x.StoreEngine("InnoDB").Sync2(tables...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (s *SSPI) Init() error {
|
||||||
Funcs: templates.NewFuncMap(),
|
Funcs: templates.NewFuncMap(),
|
||||||
Asset: templates.GetAsset,
|
Asset: templates.GetAsset,
|
||||||
AssetNames: templates.GetAssetNames,
|
AssetNames: templates.GetAssetNames,
|
||||||
IsDevelopment: setting.RunMode != "prod",
|
IsDevelopment: !setting.IsProd(),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
// GetCacheControl returns a suitable "Cache-Control" header value
|
// GetCacheControl returns a suitable "Cache-Control" header value
|
||||||
func GetCacheControl() string {
|
func GetCacheControl() string {
|
||||||
if setting.RunMode == "dev" {
|
if !setting.IsProd() {
|
||||||
return "no-store"
|
return "no-store"
|
||||||
}
|
}
|
||||||
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)
|
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)
|
||||||
|
|
|
@ -376,7 +376,6 @@ var (
|
||||||
CustomConf string
|
CustomConf string
|
||||||
PIDFile = "/run/gitea.pid"
|
PIDFile = "/run/gitea.pid"
|
||||||
WritePIDFile bool
|
WritePIDFile bool
|
||||||
ProdMode bool
|
|
||||||
RunMode string
|
RunMode string
|
||||||
RunUser string
|
RunUser string
|
||||||
IsWindows bool
|
IsWindows bool
|
||||||
|
@ -388,6 +387,11 @@ var (
|
||||||
UILocation = time.Local
|
UILocation = time.Local
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsProd if it's a production mode
|
||||||
|
func IsProd() bool {
|
||||||
|
return strings.EqualFold(RunMode, "prod")
|
||||||
|
}
|
||||||
|
|
||||||
func getAppPath() (string, error) {
|
func getAppPath() (string, error) {
|
||||||
var appPath string
|
var appPath string
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -50,7 +50,7 @@ func checkRunMode() {
|
||||||
default:
|
default:
|
||||||
macaron.Env = macaron.PROD
|
macaron.Env = macaron.PROD
|
||||||
macaron.ColorLog = false
|
macaron.ColorLog = false
|
||||||
setting.ProdMode = true
|
git.Debug = false
|
||||||
}
|
}
|
||||||
log.Info("Run Mode: %s", strings.Title(macaron.Env))
|
log.Info("Run Mode: %s", strings.Title(macaron.Env))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// Although similar to macaron.Recovery() the main difference is that this error will be created
|
||||||
// with the gitea 500 page.
|
// with the gitea 500 page.
|
||||||
func Recovery() func(next http.Handler) http.Handler {
|
func Recovery() func(next http.Handler) http.Handler {
|
||||||
var isDevelopment = setting.RunMode != "prod"
|
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
rnd := render.New(render.Options{
|
rnd := render.New(render.Options{
|
||||||
Extensions: []string{".tmpl"},
|
Extensions: []string{".tmpl"},
|
||||||
|
@ -37,7 +36,7 @@ func Recovery() func(next http.Handler) http.Handler {
|
||||||
Funcs: templates.NewFuncMap(),
|
Funcs: templates.NewFuncMap(),
|
||||||
Asset: templates.GetAsset,
|
Asset: templates.GetAsset,
|
||||||
AssetNames: templates.GetAssetNames,
|
AssetNames: templates.GetAssetNames,
|
||||||
IsDevelopment: isDevelopment,
|
IsDevelopment: !setting.IsProd(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
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 {
|
if err := recover(); err != nil {
|
||||||
combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
|
combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
|
||||||
log.Error(combinedErr)
|
log.Error(combinedErr)
|
||||||
if isDevelopment {
|
if setting.IsProd() {
|
||||||
http.Error(w, combinedErr, 500)
|
|
||||||
} else {
|
|
||||||
http.Error(w, http.StatusText(500), 500)
|
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`)
|
w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
|
||||||
|
|
||||||
if setting.RunMode != "prod" {
|
if !setting.IsProd() {
|
||||||
store.Data["ErrorMsg"] = combinedErr
|
store.Data["ErrorMsg"] = combinedErr
|
||||||
}
|
}
|
||||||
err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data))
|
err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data))
|
||||||
|
|
Loading…
Reference in New Issue