Skip to content

Commit cf045b0

Browse files
authored
golint fixed for parts of routers root, dev, user and org dirs (#167)
* golint fixed for parts of routers root, dev and org dirs * add user/auth.go golint fixed * rename unnecessary exported to unexported and user dir golint fixed
1 parent 91953ae commit cf045b0

File tree

11 files changed

+225
-132
lines changed

11 files changed

+225
-132
lines changed

routers/dev/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/setting"
1212
)
1313

14+
// TemplatePreview render for previewing the indicated template
1415
func TemplatePreview(ctx *context.Context) {
1516
ctx.Data["User"] = models.User{Name: "Unknown"}
1617
ctx.Data["AppName"] = setting.AppName

routers/home.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ import (
1717
)
1818

1919
const (
20-
HOME base.TplName = "home"
21-
EXPLORE_REPOS base.TplName = "explore/repos"
22-
EXPLORE_USERS base.TplName = "explore/users"
23-
EXPLORE_ORGANIZATIONS base.TplName = "explore/organizations"
20+
// tplHome home page template
21+
tplHome base.TplName = "home"
22+
// tplExploreRepos explore repositories page template
23+
tplExploreRepos base.TplName = "explore/repos"
24+
// tplExploreUsers explore users page template
25+
tplExploreUsers base.TplName = "explore/users"
26+
// tplExploreOrganizations explore organizations page template
27+
tplExploreOrganizations base.TplName = "explore/organizations"
2428
)
2529

30+
// Home render home page
2631
func Home(ctx *context.Context) {
2732
if ctx.IsSigned {
2833
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
2934
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
30-
ctx.HTML(200, user.ACTIVATE)
35+
ctx.HTML(200, user.TplActivate)
3136
} else {
3237
user.Dashboard(ctx)
3338
}
@@ -42,9 +47,10 @@ func Home(ctx *context.Context) {
4247
}
4348

4449
ctx.Data["PageIsHome"] = true
45-
ctx.HTML(200, HOME)
50+
ctx.HTML(200, tplHome)
4651
}
4752

53+
// RepoSearchOptions when calling search repositories
4854
type RepoSearchOptions struct {
4955
Counter func(bool) int64
5056
Ranger func(int, int) ([]*models.Repository, error)
@@ -54,6 +60,7 @@ type RepoSearchOptions struct {
5460
TplName base.TplName
5561
}
5662

63+
// RenderRepoSearch render repositories search page
5764
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
5865
page := ctx.QueryInt("page")
5966
if page <= 0 {
@@ -102,6 +109,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
102109
ctx.HTML(200, opts.TplName)
103110
}
104111

112+
// ExploreRepos render explore repositories page
105113
func ExploreRepos(ctx *context.Context) {
106114
ctx.Data["Title"] = ctx.Tr("explore")
107115
ctx.Data["PageIsExplore"] = true
@@ -112,10 +120,11 @@ func ExploreRepos(ctx *context.Context) {
112120
Ranger: models.GetRecentUpdatedRepositories,
113121
PageSize: setting.UI.ExplorePagingNum,
114122
OrderBy: "updated_unix DESC",
115-
TplName: EXPLORE_REPOS,
123+
TplName: tplExploreRepos,
116124
})
117125
}
118126

127+
// UserSearchOptions options when render search user page
119128
type UserSearchOptions struct {
120129
Type models.UserType
121130
Counter func() int64
@@ -125,6 +134,7 @@ type UserSearchOptions struct {
125134
TplName base.TplName
126135
}
127136

137+
// RenderUserSearch render user search page
128138
func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
129139
page := ctx.QueryInt("page")
130140
if page <= 1 {
@@ -166,6 +176,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
166176
ctx.HTML(200, opts.TplName)
167177
}
168178

179+
// ExploreUsers render explore users page
169180
func ExploreUsers(ctx *context.Context) {
170181
ctx.Data["Title"] = ctx.Tr("explore")
171182
ctx.Data["PageIsExplore"] = true
@@ -177,10 +188,11 @@ func ExploreUsers(ctx *context.Context) {
177188
Ranger: models.Users,
178189
PageSize: setting.UI.ExplorePagingNum,
179190
OrderBy: "name ASC",
180-
TplName: EXPLORE_USERS,
191+
TplName: tplExploreUsers,
181192
})
182193
}
183194

195+
// ExploreOrganizations render explore organizations page
184196
func ExploreOrganizations(ctx *context.Context) {
185197
ctx.Data["Title"] = ctx.Tr("explore")
186198
ctx.Data["PageIsExplore"] = true
@@ -192,10 +204,11 @@ func ExploreOrganizations(ctx *context.Context) {
192204
Ranger: models.Organizations,
193205
PageSize: setting.UI.ExplorePagingNum,
194206
OrderBy: "name ASC",
195-
TplName: EXPLORE_ORGANIZATIONS,
207+
TplName: tplExploreOrganizations,
196208
})
197209
}
198210

211+
// NotFound render 404 page
199212
func NotFound(ctx *context.Context) {
200213
ctx.Data["Title"] = "Page Not Found"
201214
ctx.Handle(404, "home.NotFound", nil)

routers/install.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import (
3434
)
3535

3636
const (
37-
INSTALL base.TplName = "install"
37+
// tplInstall template for installation page
38+
tplInstall base.TplName = "install"
3839
)
3940

4041
func checkRunMode() {
@@ -49,6 +50,7 @@ func checkRunMode() {
4950
log.Info("Run Mode: %s", strings.Title(macaron.Env))
5051
}
5152

53+
// NewServices init new services
5254
func NewServices() {
5355
setting.NewServices()
5456
mailer.NewContext()
@@ -97,6 +99,7 @@ func GlobalInit() {
9799
}
98100
}
99101

102+
// InstallInit prepare for rendering installation page
100103
func InstallInit(ctx *context.Context) {
101104
if setting.InstallLock {
102105
ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
@@ -116,6 +119,7 @@ func InstallInit(ctx *context.Context) {
116119
ctx.Data["DbOptions"] = dbOpts
117120
}
118121

122+
// Install render installation page
119123
func Install(ctx *context.Context) {
120124
form := auth.InstallForm{}
121125

@@ -175,9 +179,10 @@ func Install(ctx *context.Context) {
175179
form.RequireSignInView = setting.Service.RequireSignInView
176180

177181
auth.AssignForm(form, ctx.Data)
178-
ctx.HTML(200, INSTALL)
182+
ctx.HTML(200, tplInstall)
179183
}
180184

185+
// InstallPost response for submit install items
181186
func InstallPost(ctx *context.Context, form auth.InstallForm) {
182187
ctx.Data["CurDbOption"] = form.DbType
183188

@@ -191,12 +196,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
191196
ctx.Data["Err_Admin"] = true
192197
}
193198

194-
ctx.HTML(200, INSTALL)
199+
ctx.HTML(200, tplInstall)
195200
return
196201
}
197202

198203
if _, err := exec.LookPath("git"); err != nil {
199-
ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), INSTALL, &form)
204+
ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), tplInstall, &form)
200205
return
201206
}
202207

@@ -214,12 +219,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
214219
if (models.DbCfg.Type == "sqlite3" || models.DbCfg.Type == "tidb") &&
215220
len(models.DbCfg.Path) == 0 {
216221
ctx.Data["Err_DbPath"] = true
217-
ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), INSTALL, &form)
222+
ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), tplInstall, &form)
218223
return
219224
} else if models.DbCfg.Type == "tidb" &&
220225
strings.ContainsAny(path.Base(models.DbCfg.Path), ".-") {
221226
ctx.Data["Err_DbPath"] = true
222-
ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), INSTALL, &form)
227+
ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), tplInstall, &form)
223228
return
224229
}
225230

@@ -228,10 +233,10 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
228233
if err := models.NewTestEngine(x); err != nil {
229234
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
230235
ctx.Data["Err_DbType"] = true
231-
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form)
236+
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), tplInstall, &form)
232237
} else {
233238
ctx.Data["Err_DbSetting"] = true
234-
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), INSTALL, &form)
239+
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), tplInstall, &form)
235240
}
236241
return
237242
}
@@ -240,44 +245,44 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
240245
form.RepoRootPath = strings.Replace(form.RepoRootPath, "\\", "/", -1)
241246
if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
242247
ctx.Data["Err_RepoRootPath"] = true
243-
ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), INSTALL, &form)
248+
ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), tplInstall, &form)
244249
return
245250
}
246251

247252
// Test log root path.
248253
form.LogRootPath = strings.Replace(form.LogRootPath, "\\", "/", -1)
249254
if err := os.MkdirAll(form.LogRootPath, os.ModePerm); err != nil {
250255
ctx.Data["Err_LogRootPath"] = true
251-
ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), INSTALL, &form)
256+
ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), tplInstall, &form)
252257
return
253258
}
254259

255260
currentUser, match := setting.IsRunUserMatchCurrentUser(form.RunUser)
256261
if !match {
257262
ctx.Data["Err_RunUser"] = true
258-
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), INSTALL, &form)
263+
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), tplInstall, &form)
259264
return
260265
}
261266

262267
// Check logic loophole between disable self-registration and no admin account.
263268
if form.DisableRegistration && len(form.AdminName) == 0 {
264269
ctx.Data["Err_Services"] = true
265270
ctx.Data["Err_Admin"] = true
266-
ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), INSTALL, form)
271+
ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), tplInstall, form)
267272
return
268273
}
269274

270275
// Check admin password.
271276
if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 {
272277
ctx.Data["Err_Admin"] = true
273278
ctx.Data["Err_AdminPasswd"] = true
274-
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), INSTALL, form)
279+
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form)
275280
return
276281
}
277282
if form.AdminPasswd != form.AdminConfirmPasswd {
278283
ctx.Data["Err_Admin"] = true
279284
ctx.Data["Err_AdminPasswd"] = true
280-
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form)
285+
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form)
281286
return
282287
}
283288

@@ -347,12 +352,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
347352

348353
err := os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
349354
if err != nil {
350-
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
355+
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
351356
return
352357
}
353358

354359
if err := cfg.SaveTo(setting.CustomConf); err != nil {
355-
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
360+
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
356361
return
357362
}
358363

@@ -372,7 +377,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
372377
setting.InstallLock = false
373378
ctx.Data["Err_AdminName"] = true
374379
ctx.Data["Err_AdminEmail"] = true
375-
ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), INSTALL, &form)
380+
ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), tplInstall, &form)
376381
return
377382
}
378383
log.Info("Admin account already exist")
@@ -381,11 +386,11 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
381386

382387
// Auto-login for admin
383388
if err := ctx.Session.Set("uid", u.ID); err != nil {
384-
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
389+
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
385390
return
386391
}
387392
if err := ctx.Session.Set("uname", u.Name); err != nil {
388-
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
393+
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
389394
return
390395
}
391396
}

routers/org/members.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import (
1515
)
1616

1717
const (
18-
MEMBERS base.TplName = "org/member/members"
19-
MEMBER_INVITE base.TplName = "org/member/invite"
18+
// tplMembers template for organization members page
19+
tplMembers base.TplName = "org/member/members"
20+
// tplMemberInvite template for orgnization invite page
21+
tplMemberInvite base.TplName = "org/member/invite"
2022
)
2123

24+
// Members render orgnization users page
2225
func Members(ctx *context.Context) {
2326
org := ctx.Org.Organization
2427
ctx.Data["Title"] = org.FullName
@@ -30,9 +33,10 @@ func Members(ctx *context.Context) {
3033
}
3134
ctx.Data["Members"] = org.Members
3235

33-
ctx.HTML(200, MEMBERS)
36+
ctx.HTML(200, tplMembers)
3437
}
3538

39+
// MembersAction response for operation to a member of orgnization
3640
func MembersAction(ctx *context.Context) {
3741
uid := com.StrTo(ctx.Query("uid")).MustInt64()
3842
if uid == 0 {
@@ -91,6 +95,7 @@ func MembersAction(ctx *context.Context) {
9195
}
9296
}
9397

98+
// Invitation render organization invitation page
9499
func Invitation(ctx *context.Context) {
95100
org := ctx.Org.Organization
96101
ctx.Data["Title"] = org.FullName
@@ -119,5 +124,5 @@ func Invitation(ctx *context.Context) {
119124
return
120125
}
121126

122-
ctx.HTML(200, MEMBER_INVITE)
127+
ctx.HTML(200, tplMemberInvite)
123128
}

routers/org/org.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ import (
1414
)
1515

1616
const (
17-
CREATE base.TplName = "org/create"
17+
// tplCreateOrg template path for create organization
18+
tplCreateOrg base.TplName = "org/create"
1819
)
1920

21+
// Create render the page for create organization
2022
func Create(ctx *context.Context) {
2123
ctx.Data["Title"] = ctx.Tr("new_org")
22-
ctx.HTML(200, CREATE)
24+
ctx.HTML(200, tplCreateOrg)
2325
}
2426

27+
// CreatePost response for create organization
2528
func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
2629
ctx.Data["Title"] = ctx.Tr("new_org")
2730

2831
if ctx.HasError() {
29-
ctx.HTML(200, CREATE)
32+
ctx.HTML(200, tplCreateOrg)
3033
return
3134
}
3235

@@ -40,11 +43,11 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
4043
ctx.Data["Err_OrgName"] = true
4144
switch {
4245
case models.IsErrUserAlreadyExist(err):
43-
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form)
46+
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
4447
case models.IsErrNameReserved(err):
45-
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form)
48+
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
4649
case models.IsErrNamePatternNotAllowed(err):
47-
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form)
50+
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
4851
default:
4952
ctx.Handle(500, "CreateOrganization", err)
5053
}

0 commit comments

Comments
 (0)