Skip to content

Commit 6ed7f26

Browse files
authored
Move init functions from routers/install to routers/init (#230)
* move init functions from routers/install to routers/init * copyright typo
1 parent 3917ed4 commit 6ed7f26

File tree

2 files changed

+82
-69
lines changed

2 files changed

+82
-69
lines changed

routers/init.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2016 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package routers
6+
7+
import (
8+
"path"
9+
"strings"
10+
11+
"code.gitea.io/git"
12+
"code.gitea.io/gitea/models"
13+
"code.gitea.io/gitea/modules/cron"
14+
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/mailer"
16+
"code.gitea.io/gitea/modules/markdown"
17+
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/modules/ssh"
19+
"code.gitea.io/gitea/modules/template/highlight"
20+
macaron "gopkg.in/macaron.v1"
21+
)
22+
23+
func checkRunMode() {
24+
switch setting.Cfg.Section("").Key("RUN_MODE").String() {
25+
case "prod":
26+
macaron.Env = macaron.PROD
27+
macaron.ColorLog = false
28+
setting.ProdMode = true
29+
default:
30+
git.Debug = true
31+
}
32+
log.Info("Run Mode: %s", strings.Title(macaron.Env))
33+
}
34+
35+
// NewServices init new services
36+
func NewServices() {
37+
setting.NewServices()
38+
mailer.NewContext()
39+
}
40+
41+
// GlobalInit is for global configuration reload-able.
42+
func GlobalInit() {
43+
setting.NewContext()
44+
log.Trace("Custom path: %s", setting.CustomPath)
45+
log.Trace("Log path: %s", setting.LogRootPath)
46+
models.LoadConfigs()
47+
NewServices()
48+
49+
if setting.InstallLock {
50+
highlight.NewContext()
51+
markdown.BuildSanitizer()
52+
if err := models.NewEngine(); err != nil {
53+
log.Fatal(4, "Fail to initialize ORM engine: %v", err)
54+
}
55+
models.HasEngine = true
56+
57+
models.LoadRepoConfig()
58+
models.NewRepoContext()
59+
60+
// Booting long running goroutines.
61+
cron.NewContext()
62+
models.InitSyncMirrors()
63+
models.InitDeliverHooks()
64+
models.InitTestPullRequests()
65+
log.NewGitLogger(path.Join(setting.LogRootPath, "http.log"))
66+
}
67+
if models.EnableSQLite3 {
68+
log.Info("SQLite3 Supported")
69+
}
70+
if models.EnableTiDB {
71+
log.Info("TiDB Supported")
72+
}
73+
if setting.SupportMiniWinService {
74+
log.Info("Builtin Windows Service Supported")
75+
}
76+
checkRunMode()
77+
78+
if setting.InstallLock && setting.SSH.StartBuiltinServer {
79+
ssh.Listen(setting.SSH.ListenPort)
80+
log.Info("SSH server started on :%v", setting.SSH.ListenPort)
81+
}
82+
}

routers/install.go

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ import (
1515
"github.com/Unknwon/com"
1616
"github.com/go-xorm/xorm"
1717
"gopkg.in/ini.v1"
18-
"gopkg.in/macaron.v1"
19-
20-
"code.gitea.io/git"
2118

2219
"code.gitea.io/gitea/models"
2320
"code.gitea.io/gitea/modules/auth"
2421
"code.gitea.io/gitea/modules/base"
2522
"code.gitea.io/gitea/modules/context"
26-
"code.gitea.io/gitea/modules/cron"
2723
"code.gitea.io/gitea/modules/log"
28-
"code.gitea.io/gitea/modules/mailer"
29-
"code.gitea.io/gitea/modules/markdown"
3024
"code.gitea.io/gitea/modules/setting"
31-
"code.gitea.io/gitea/modules/ssh"
32-
"code.gitea.io/gitea/modules/template/highlight"
3325
"code.gitea.io/gitea/modules/user"
3426
)
3527

@@ -38,67 +30,6 @@ const (
3830
tplInstall base.TplName = "install"
3931
)
4032

41-
func checkRunMode() {
42-
switch setting.Cfg.Section("").Key("RUN_MODE").String() {
43-
case "prod":
44-
macaron.Env = macaron.PROD
45-
macaron.ColorLog = false
46-
setting.ProdMode = true
47-
default:
48-
git.Debug = true
49-
}
50-
log.Info("Run Mode: %s", strings.Title(macaron.Env))
51-
}
52-
53-
// NewServices init new services
54-
func NewServices() {
55-
setting.NewServices()
56-
mailer.NewContext()
57-
}
58-
59-
// GlobalInit is for global configuration reload-able.
60-
func GlobalInit() {
61-
setting.NewContext()
62-
log.Trace("Custom path: %s", setting.CustomPath)
63-
log.Trace("Log path: %s", setting.LogRootPath)
64-
models.LoadConfigs()
65-
NewServices()
66-
67-
if setting.InstallLock {
68-
highlight.NewContext()
69-
markdown.BuildSanitizer()
70-
if err := models.NewEngine(); err != nil {
71-
log.Fatal(4, "Fail to initialize ORM engine: %v", err)
72-
}
73-
models.HasEngine = true
74-
75-
models.LoadRepoConfig()
76-
models.NewRepoContext()
77-
78-
// Booting long running goroutines.
79-
cron.NewContext()
80-
models.InitSyncMirrors()
81-
models.InitDeliverHooks()
82-
models.InitTestPullRequests()
83-
log.NewGitLogger(path.Join(setting.LogRootPath, "http.log"))
84-
}
85-
if models.EnableSQLite3 {
86-
log.Info("SQLite3 Supported")
87-
}
88-
if models.EnableTiDB {
89-
log.Info("TiDB Supported")
90-
}
91-
if setting.SupportMiniWinService {
92-
log.Info("Builtin Windows Service Supported")
93-
}
94-
checkRunMode()
95-
96-
if setting.InstallLock && setting.SSH.StartBuiltinServer {
97-
ssh.Listen(setting.SSH.ListenPort)
98-
log.Info("SSH server started on :%v", setting.SSH.ListenPort)
99-
}
100-
}
101-
10233
// InstallInit prepare for rendering installation page
10334
func InstallInit(ctx *context.Context) {
10435
if setting.InstallLock {

0 commit comments

Comments
 (0)