conf: overhaul server settings (#5928)

* conf: rename package

* Requires Go 1.12

* Fix lint

* Fix lint

* Overhaul

* db: fix tests

* Save my work

* Fix tests

* Server.UnixSocketPermission

* Server.LocalRootURL

* SSH settings

* Server.OfflineMode

* Save my work

* App.Version

* Remove [server] STATIC_ROOT_PATH

* Server.LandingURL
This commit is contained in:
ᴜɴᴋɴᴡᴏɴ
2020-02-22 09:05:26 +08:00
committed by GitHub
parent 5b14cc6f0b
commit 648d9e253c
102 changed files with 1464 additions and 1329 deletions

View File

@@ -16,9 +16,9 @@ import (
"github.com/urfave/cli"
log "unknwon.dev/clog/v2"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/setting"
)
const (
@@ -39,7 +39,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
fmt.Fprintln(os.Stderr, "Gogs:", userMessage)
if len(logMessage) > 0 {
if !setting.ProdMode {
if !conf.IsProdMode() {
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
}
log.Fatal(logMessage, args...)
@@ -49,22 +49,26 @@ func fail(userMessage, logMessage string, args ...interface{}) {
}
func setup(c *cli.Context, logPath string, connectDB bool) {
var customConf string
if c.IsSet("config") {
setting.CustomConf = c.String("config")
customConf = c.String("config")
} else if c.GlobalIsSet("config") {
setting.CustomConf = c.GlobalString("config")
customConf = c.GlobalString("config")
}
setting.Init()
err := conf.Init(customConf)
if err != nil {
fail("Internal error", "Failed to init configuration: %v", err)
}
level := log.LevelTrace
if setting.ProdMode {
if conf.IsProdMode() {
level = log.LevelError
}
err := log.NewFile(log.FileConfig{
err = log.NewFile(log.FileConfig{
Level: level,
Filename: filepath.Join(setting.LogRootPath, logPath),
Filename: filepath.Join(conf.LogRootPath, logPath),
FileRotationConfig: log.FileRotationConfig{
Rotate: true,
Daily: true,
@@ -72,8 +76,7 @@ func setup(c *cli.Context, logPath string, connectDB bool) {
},
})
if err != nil {
log.Fatal("Failed to init file logger: %v", err)
return
fail("Internal error", "Failed to init file logger: %v", err)
}
log.Remove(log.DefaultConsoleName) // Remove the primary logger
@@ -83,13 +86,12 @@ func setup(c *cli.Context, logPath string, connectDB bool) {
db.LoadConfigs()
if setting.UseSQLite3 {
workDir, _ := setting.WorkDir()
os.Chdir(workDir)
if conf.UseSQLite3 {
_ = os.Chdir(conf.WorkDir())
}
if err := db.SetEngine(); err != nil {
fail("Internal error", "SetEngine: %v", err)
fail("Internal error", "Failed to set database engine: %v", err)
}
}
@@ -130,7 +132,7 @@ var (
func runServ(c *cli.Context) error {
setup(c, "serv.log", true)
if setting.SSH.Disabled {
if conf.SSH.Disabled {
println("Gogs: SSH has been disabled")
return nil
}
@@ -220,12 +222,12 @@ func runServ(c *cli.Context) error {
}
}
} else {
setting.NewService()
conf.NewService()
// Check if the key can access to the repository in case of it is a deploy key (a deploy keys != user key).
// A deploy key doesn't represent a signed in user, so in a site with Service.RequireSignInView activated
// we should give read access only in repositories where this deploy key is in use. In other case, a server
// or system using an active deploy key can get read access to all the repositories in a Gogs service.
if key.IsDeployKey() && setting.Service.RequireSignInView {
if key.IsDeployKey() && conf.Service.RequireSignInView {
checkDeployKey(key, repo)
}
}
@@ -244,7 +246,7 @@ func runServ(c *cli.Context) error {
}
// Special handle for Windows.
if setting.IsWindows {
if conf.IsWindowsRuntime() {
verb = strings.Replace(verb, "-", " ", 1)
}
@@ -265,7 +267,7 @@ func runServ(c *cli.Context) error {
RepoPath: repo.RepoPath(),
})...)
}
gitCmd.Dir = setting.RepoRootPath
gitCmd.Dir = conf.RepoRootPath
gitCmd.Stdout = os.Stdout
gitCmd.Stdin = os.Stdin
gitCmd.Stderr = os.Stderr