Skip to content

Commit 1d9576d

Browse files
authored
Merge pull request #202 from lunny/lunny/golint_fixed_routers_admin
go lint fixed for routers/admin
2 parents bd13c81 + 659bc28 commit 1d9576d

File tree

6 files changed

+73
-51
lines changed

6 files changed

+73
-51
lines changed

routers/admin/admin.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
)
2323

2424
const (
25-
DASHBOARD base.TplName = "admin/dashboard"
26-
CONFIG base.TplName = "admin/config"
27-
MONITOR base.TplName = "admin/monitor"
25+
tplDashboard base.TplName = "admin/dashboard"
26+
tplConfig base.TplName = "admin/config"
27+
tplMonitor base.TplName = "admin/monitor"
2828
)
2929

3030
var (
@@ -110,19 +110,20 @@ func updateSystemStatus() {
110110
sysStatus.NumGC = m.NumGC
111111
}
112112

113-
// Operation types.
114-
type AdminOperation int
113+
// Operation Operation types.
114+
type Operation int
115115

116116
const (
117-
CLEAN_INACTIVATE_USER AdminOperation = iota + 1
118-
CLEAN_REPO_ARCHIVES
119-
CLEAN_MISSING_REPOS
120-
GIT_GC_REPOS
121-
SYNC_SSH_AUTHORIZED_KEY
122-
SYNC_REPOSITORY_UPDATE_HOOK
123-
REINIT_MISSING_REPOSITORY
117+
cleanInactivateUser Operation = iota + 1
118+
cleanRepoArchives
119+
cleanMissingRepos
120+
gitGCRepos
121+
syncSSHAuthorizedKey
122+
syncRepositoryUpdateHook
123+
reinitMissingRepository
124124
)
125125

126+
// Dashboard show admin panel dashboard
126127
func Dashboard(ctx *context.Context) {
127128
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
128129
ctx.Data["PageIsAdmin"] = true
@@ -134,26 +135,26 @@ func Dashboard(ctx *context.Context) {
134135
var err error
135136
var success string
136137

137-
switch AdminOperation(op) {
138-
case CLEAN_INACTIVATE_USER:
138+
switch Operation(op) {
139+
case cleanInactivateUser:
139140
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
140141
err = models.DeleteInactivateUsers()
141-
case CLEAN_REPO_ARCHIVES:
142+
case cleanRepoArchives:
142143
success = ctx.Tr("admin.dashboard.delete_repo_archives_success")
143144
err = models.DeleteRepositoryArchives()
144-
case CLEAN_MISSING_REPOS:
145+
case cleanMissingRepos:
145146
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
146147
err = models.DeleteMissingRepositories()
147-
case GIT_GC_REPOS:
148+
case gitGCRepos:
148149
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
149150
err = models.GitGcRepos()
150-
case SYNC_SSH_AUTHORIZED_KEY:
151+
case syncSSHAuthorizedKey:
151152
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
152153
err = models.RewriteAllPublicKeys()
153-
case SYNC_REPOSITORY_UPDATE_HOOK:
154+
case syncRepositoryUpdateHook:
154155
success = ctx.Tr("admin.dashboard.resync_all_update_hooks_success")
155156
err = models.RewriteRepositoryUpdateHook()
156-
case REINIT_MISSING_REPOSITORY:
157+
case reinitMissingRepository:
157158
success = ctx.Tr("admin.dashboard.reinit_missing_repos_success")
158159
err = models.ReinitMissingRepositories()
159160
}
@@ -171,9 +172,10 @@ func Dashboard(ctx *context.Context) {
171172
// FIXME: update periodically
172173
updateSystemStatus()
173174
ctx.Data["SysStatus"] = sysStatus
174-
ctx.HTML(200, DASHBOARD)
175+
ctx.HTML(200, tplDashboard)
175176
}
176177

178+
// SendTestMail send test mail to confirm mail service is OK
177179
func SendTestMail(ctx *context.Context) {
178180
email := ctx.Query("email")
179181
// Send a test email to the user's email address and redirect back to Config
@@ -186,6 +188,7 @@ func SendTestMail(ctx *context.Context) {
186188
ctx.Redirect(setting.AppSubUrl + "/admin/config")
187189
}
188190

191+
// Config show admin config page
189192
func Config(ctx *context.Context) {
190193
ctx.Data["Title"] = ctx.Tr("admin.config")
191194
ctx.Data["PageIsAdmin"] = true
@@ -235,14 +238,15 @@ func Config(ctx *context.Context) {
235238
}
236239
ctx.Data["Loggers"] = loggers
237240

238-
ctx.HTML(200, CONFIG)
241+
ctx.HTML(200, tplConfig)
239242
}
240243

244+
// Monitor show admin monitor page
241245
func Monitor(ctx *context.Context) {
242246
ctx.Data["Title"] = ctx.Tr("admin.monitor")
243247
ctx.Data["PageIsAdmin"] = true
244248
ctx.Data["PageIsAdminMonitor"] = true
245249
ctx.Data["Processes"] = process.Processes
246250
ctx.Data["Entries"] = cron.ListTasks()
247-
ctx.HTML(200, MONITOR)
251+
ctx.HTML(200, tplMonitor)
248252
}

routers/admin/auths.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
)
2121

2222
const (
23-
AUTHS base.TplName = "admin/auth/list"
24-
AUTH_NEW base.TplName = "admin/auth/new"
25-
AUTH_EDIT base.TplName = "admin/auth/edit"
23+
tplAuths base.TplName = "admin/auth/list"
24+
tplAuthNew base.TplName = "admin/auth/new"
25+
tplAuthEdit base.TplName = "admin/auth/edit"
2626
)
2727

28+
// Authentications show authentication config page
2829
func Authentications(ctx *context.Context) {
2930
ctx.Data["Title"] = ctx.Tr("admin.authentication")
3031
ctx.Data["PageIsAdmin"] = true
@@ -38,7 +39,7 @@ func Authentications(ctx *context.Context) {
3839
}
3940

4041
ctx.Data["Total"] = models.CountLoginSources()
41-
ctx.HTML(200, AUTHS)
42+
ctx.HTML(200, tplAuths)
4243
}
4344

4445
type dropdownItem struct {
@@ -60,6 +61,7 @@ var (
6061
}
6162
)
6263

64+
// NewAuthSource render adding a new auth source page
6365
func NewAuthSource(ctx *context.Context) {
6466
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
6567
ctx.Data["PageIsAdmin"] = true
@@ -73,7 +75,7 @@ func NewAuthSource(ctx *context.Context) {
7375
ctx.Data["AuthSources"] = authSources
7476
ctx.Data["SecurityProtocols"] = securityProtocols
7577
ctx.Data["SMTPAuths"] = models.SMTPAuths
76-
ctx.HTML(200, AUTH_NEW)
78+
ctx.HTML(200, tplAuthNew)
7779
}
7880

7981
func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
@@ -111,6 +113,7 @@ func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
111113
}
112114
}
113115

116+
// NewAuthSourcePost response for adding an auth source
114117
func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
115118
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
116119
ctx.Data["PageIsAdmin"] = true
@@ -142,7 +145,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
142145
ctx.Data["HasTLS"] = hasTLS
143146

144147
if ctx.HasError() {
145-
ctx.HTML(200, AUTH_NEW)
148+
ctx.HTML(200, tplAuthNew)
146149
return
147150
}
148151

@@ -154,7 +157,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
154157
}); err != nil {
155158
if models.IsErrLoginSourceAlreadyExist(err) {
156159
ctx.Data["Err_Name"] = true
157-
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, form)
160+
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
158161
} else {
159162
ctx.Handle(500, "CreateSource", err)
160163
}
@@ -167,6 +170,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
167170
ctx.Redirect(setting.AppSubUrl + "/admin/auths")
168171
}
169172

173+
// EditAuthSource render editing auth source page
170174
func EditAuthSource(ctx *context.Context) {
171175
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
172176
ctx.Data["PageIsAdmin"] = true
@@ -183,9 +187,10 @@ func EditAuthSource(ctx *context.Context) {
183187
ctx.Data["Source"] = source
184188
ctx.Data["HasTLS"] = source.HasTLS()
185189

186-
ctx.HTML(200, AUTH_EDIT)
190+
ctx.HTML(200, tplAuthEdit)
187191
}
188192

193+
// EditAuthSourcePost resposne for editing auth source
189194
func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
190195
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
191196
ctx.Data["PageIsAdmin"] = true
@@ -202,7 +207,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
202207
ctx.Data["HasTLS"] = source.HasTLS()
203208

204209
if ctx.HasError() {
205-
ctx.HTML(200, AUTH_EDIT)
210+
ctx.HTML(200, tplAuthEdit)
206211
return
207212
}
208213

@@ -234,6 +239,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
234239
ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID))
235240
}
236241

242+
// DeleteAuthSource response for deleting an auth source
237243
func DeleteAuthSource(ctx *context.Context) {
238244
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
239245
if err != nil {

routers/admin/notice.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616
)
1717

1818
const (
19-
NOTICES base.TplName = "admin/notice"
19+
tplNotices base.TplName = "admin/notice"
2020
)
2121

22+
// Notices show notices for admin
2223
func Notices(ctx *context.Context) {
2324
ctx.Data["Title"] = ctx.Tr("admin.notices")
2425
ctx.Data["PageIsAdmin"] = true
@@ -39,9 +40,10 @@ func Notices(ctx *context.Context) {
3940
ctx.Data["Notices"] = notices
4041

4142
ctx.Data["Total"] = total
42-
ctx.HTML(200, NOTICES)
43+
ctx.HTML(200, tplNotices)
4344
}
4445

46+
// DeleteNotices delete the specific notices
4547
func DeleteNotices(ctx *context.Context) {
4648
strs := ctx.QueryStrings("ids[]")
4749
ids := make([]int64, 0, len(strs))
@@ -61,6 +63,7 @@ func DeleteNotices(ctx *context.Context) {
6163
}
6264
}
6365

66+
// EmptyNotices delete all the notices
6467
func EmptyNotices(ctx *context.Context) {
6568
if err := models.DeleteNotices(0, 0); err != nil {
6669
ctx.Handle(500, "DeleteNotices", err)

routers/admin/orgs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
)
1414

1515
const (
16-
ORGS base.TplName = "admin/org/list"
16+
tplOrgs base.TplName = "admin/org/list"
1717
)
1818

19+
// Organizations show all the organizations
1920
func Organizations(ctx *context.Context) {
2021
ctx.Data["Title"] = ctx.Tr("admin.organizations")
2122
ctx.Data["PageIsAdmin"] = true
@@ -27,6 +28,6 @@ func Organizations(ctx *context.Context) {
2728
Ranger: models.Organizations,
2829
PageSize: setting.UI.Admin.OrgPagingNum,
2930
OrderBy: "id ASC",
30-
TplName: ORGS,
31+
TplName: tplOrgs,
3132
})
3233
}

routers/admin/repos.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
)
1515

1616
const (
17-
REPOS base.TplName = "admin/repo/list"
17+
tplRepos base.TplName = "admin/repo/list"
1818
)
1919

20+
// Repos show all the repositories
2021
func Repos(ctx *context.Context) {
2122
ctx.Data["Title"] = ctx.Tr("admin.repositories")
2223
ctx.Data["PageIsAdmin"] = true
@@ -28,10 +29,11 @@ func Repos(ctx *context.Context) {
2829
Private: true,
2930
PageSize: setting.UI.Admin.RepoPagingNum,
3031
OrderBy: "owner_id ASC, name ASC, id ASC",
31-
TplName: REPOS,
32+
TplName: tplRepos,
3233
})
3334
}
3435

36+
// DeleteRepo delete one repository
3537
func DeleteRepo(ctx *context.Context) {
3638
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
3739
if err != nil {

0 commit comments

Comments
 (0)