Skip to content

Commit 4f2f3c2

Browse files
committed
Code convention
1 parent 11f9d73 commit 4f2f3c2

File tree

11 files changed

+83
-80
lines changed

11 files changed

+83
-80
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
55

66
![Demo](http://gowalker.org/public/gogs_demo.gif)
77

8-
##### Current version: 0.4.0 Alpha
8+
##### Current version: 0.4.2 Alpha
99

1010
### NOTICES
1111

README_ZH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
55

66
![Demo](http://gowalker.org/public/gogs_demo.gif)
77

8-
##### 当前版本:0.4.0 Alpha
8+
##### 当前版本:0.4.2 Alpha
99

1010
## 开发目的
1111

cmd/web.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ func runWeb(*cli.Context) {
8989
m.Get("/", ignSignIn, routers.Home)
9090
m.Get("/install", bindIgnErr(auth.InstallForm{}), routers.Install)
9191
m.Post("/install", bindIgnErr(auth.InstallForm{}), routers.InstallPost)
92-
m.Get("/issues", reqSignIn, user.Issues)
93-
m.Get("/pulls", reqSignIn, user.Pulls)
94-
m.Get("/stars", reqSignIn, user.Stars)
92+
m.Group("", func(r martini.Router) {
93+
r.Get("/issues", user.Issues)
94+
r.Get("/pulls", user.Pulls)
95+
r.Get("/stars", user.Stars)
96+
}, reqSignIn)
9597

9698
m.Group("/api", func(r martini.Router) {
9799
m.Group("/v1", func(r martini.Router) {

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/gogits/gogs/modules/setting"
1818
)
1919

20-
const APP_VER = "0.4.1.0603 Alpha"
20+
const APP_VER = "0.4.2.0605 Alpha"
2121

2222
func init() {
2323
runtime.GOMAXPROCS(runtime.NumCPU())

models/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func DelLoginSource(source *LoginSource) error {
150150
return err
151151
}
152152

153-
// login a user
154-
func LoginUser(uname, passwd string) (*User, error) {
153+
// UserSignIn validates user name and password.
154+
func UserSignIn(uname, passwd string) (*User, error) {
155155
var u *User
156156
if strings.Contains(uname, "@") {
157157
u = &User{Email: uname}

models/user.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (user *User) HomeLink() string {
7272
return "/user/" + user.Name
7373
}
7474

75-
// AvatarLink returns the user gravatar link.
75+
// AvatarLink returns user gravatar link.
7676
func (user *User) AvatarLink() string {
7777
if setting.DisableGravatar {
7878
return "/img/avatar_default.jpg"
@@ -268,17 +268,17 @@ func ChangeUserName(user *User, newUserName string) (err error) {
268268
}
269269

270270
// UpdateUser updates user's information.
271-
func UpdateUser(user *User) (err error) {
272-
user.LowerName = strings.ToLower(user.Name)
271+
func UpdateUser(u *User) (err error) {
272+
u.LowerName = strings.ToLower(u.Name)
273273

274-
if len(user.Location) > 255 {
275-
user.Location = user.Location[:255]
274+
if len(u.Location) > 255 {
275+
u.Location = u.Location[:255]
276276
}
277-
if len(user.Website) > 255 {
278-
user.Website = user.Website[:255]
277+
if len(u.Website) > 255 {
278+
u.Website = u.Website[:255]
279279
}
280280

281-
_, err = orm.Id(user.Id).AllCols().Update(user)
281+
_, err = orm.Id(u.Id).AllCols().Update(u)
282282
return err
283283
}
284284

@@ -356,17 +356,16 @@ func GetUserByKeyId(keyId int64) (*User, error) {
356356
return user, nil
357357
}
358358

359-
// GetUserById returns the user object by given id if exists.
359+
// GetUserById returns the user object by given ID if exists.
360360
func GetUserById(id int64) (*User, error) {
361-
user := new(User)
362-
has, err := orm.Id(id).Get(user)
361+
u := new(User)
362+
has, err := orm.Id(id).Get(u)
363363
if err != nil {
364364
return nil, err
365-
}
366-
if !has {
365+
} else if !has {
367366
return nil, ErrUserNotExist
368367
}
369-
return user, nil
368+
return u, nil
370369
}
371370

372371
// GetUserByName returns the user object by given name if exists.

modules/auth/user.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,54 @@ import (
1919
)
2020

2121
// SignedInId returns the id of signed in user.
22-
func SignedInId(session session.SessionStore) int64 {
22+
func SignedInId(sess session.SessionStore) int64 {
2323
if !models.HasEngine {
2424
return 0
2525
}
2626

27-
userId := session.Get("userId")
28-
if userId == nil {
27+
uid := sess.Get("userId")
28+
if uid == nil {
2929
return 0
3030
}
31-
if s, ok := userId.(int64); ok {
32-
if _, err := models.GetUserById(s); err != nil {
31+
if id, ok := uid.(int64); ok {
32+
if _, err := models.GetUserById(id); err != nil {
3333
return 0
3434
}
35-
return s
35+
return id
3636
}
3737
return 0
3838
}
3939

4040
// SignedInName returns the name of signed in user.
41-
func SignedInName(session session.SessionStore) string {
42-
userName := session.Get("userName")
43-
if userName == nil {
41+
func SignedInName(sess session.SessionStore) string {
42+
uname := sess.Get("userName")
43+
if uname == nil {
4444
return ""
4545
}
46-
if s, ok := userName.(string); ok {
46+
if s, ok := uname.(string); ok {
4747
return s
4848
}
4949
return ""
5050
}
5151

5252
// SignedInUser returns the user object of signed user.
53-
func SignedInUser(session session.SessionStore) *models.User {
54-
id := SignedInId(session)
55-
if id <= 0 {
53+
func SignedInUser(sess session.SessionStore) *models.User {
54+
uid := SignedInId(sess)
55+
if uid <= 0 {
5656
return nil
5757
}
5858

59-
user, err := models.GetUserById(id)
59+
u, err := models.GetUserById(uid)
6060
if err != nil {
6161
log.Error("user.SignedInUser: %v", err)
6262
return nil
6363
}
64-
return user
64+
return u
6565
}
6666

6767
// IsSignedIn check if any user has signed in.
68-
func IsSignedIn(session session.SessionStore) bool {
69-
return SignedInId(session) > 0
68+
func IsSignedIn(sess session.SessionStore) bool {
69+
return SignedInId(sess) > 0
7070
}
7171

7272
type FeedsForm struct {

modules/mailer/mail.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,92 +29,92 @@ func NewMailMessage(To []string, subject, body string) Message {
2929
return NewMailMessageFrom(To, setting.MailService.From, subject, body)
3030
}
3131

32-
func GetMailTmplData(user *models.User) map[interface{}]interface{} {
32+
func GetMailTmplData(u *models.User) map[interface{}]interface{} {
3333
data := make(map[interface{}]interface{}, 10)
3434
data["AppName"] = setting.AppName
3535
data["AppVer"] = setting.AppVer
3636
data["AppUrl"] = setting.AppUrl
3737
data["AppLogo"] = setting.AppLogo
3838
data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
3939
data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
40-
if user != nil {
41-
data["User"] = user
40+
if u != nil {
41+
data["User"] = u
4242
}
4343
return data
4444
}
4545

4646
// create a time limit code for user active
47-
func CreateUserActiveCode(user *models.User, startInf interface{}) string {
47+
func CreateUserActiveCode(u *models.User, startInf interface{}) string {
4848
minutes := setting.Service.ActiveCodeLives
49-
data := base.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands
49+
data := base.ToStr(u.Id) + u.Email + u.LowerName + u.Passwd + u.Rands
5050
code := base.CreateTimeLimitCode(data, minutes, startInf)
5151

5252
// add tail hex username
53-
code += hex.EncodeToString([]byte(user.LowerName))
53+
code += hex.EncodeToString([]byte(u.LowerName))
5454
return code
5555
}
5656

5757
// Send user register mail with active code
58-
func SendRegisterMail(r *middleware.Render, user *models.User) {
59-
code := CreateUserActiveCode(user, nil)
58+
func SendRegisterMail(r *middleware.Render, u *models.User) {
59+
code := CreateUserActiveCode(u, nil)
6060
subject := "Register success, Welcome"
6161

62-
data := GetMailTmplData(user)
62+
data := GetMailTmplData(u)
6363
data["Code"] = code
6464
body, err := r.HTMLString("mail/auth/register_success", data)
6565
if err != nil {
6666
log.Error("mail.SendRegisterMail(fail to render): %v", err)
6767
return
6868
}
6969

70-
msg := NewMailMessage([]string{user.Email}, subject, body)
71-
msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id)
70+
msg := NewMailMessage([]string{u.Email}, subject, body)
71+
msg.Info = fmt.Sprintf("UID: %d, send register mail", u.Id)
7272

7373
SendAsync(&msg)
7474
}
7575

7676
// Send email verify active email.
77-
func SendActiveMail(r *middleware.Render, user *models.User) {
78-
code := CreateUserActiveCode(user, nil)
77+
func SendActiveMail(r *middleware.Render, u *models.User) {
78+
code := CreateUserActiveCode(u, nil)
7979

8080
subject := "Verify your e-mail address"
8181

82-
data := GetMailTmplData(user)
82+
data := GetMailTmplData(u)
8383
data["Code"] = code
8484
body, err := r.HTMLString("mail/auth/active_email", data)
8585
if err != nil {
8686
log.Error("mail.SendActiveMail(fail to render): %v", err)
8787
return
8888
}
8989

90-
msg := NewMailMessage([]string{user.Email}, subject, body)
91-
msg.Info = fmt.Sprintf("UID: %d, send active mail", user.Id)
90+
msg := NewMailMessage([]string{u.Email}, subject, body)
91+
msg.Info = fmt.Sprintf("UID: %d, send active mail", u.Id)
9292

9393
SendAsync(&msg)
9494
}
9595

9696
// Send reset password email.
97-
func SendResetPasswdMail(r *middleware.Render, user *models.User) {
98-
code := CreateUserActiveCode(user, nil)
97+
func SendResetPasswdMail(r *middleware.Render, u *models.User) {
98+
code := CreateUserActiveCode(u, nil)
9999

100100
subject := "Reset your password"
101101

102-
data := GetMailTmplData(user)
102+
data := GetMailTmplData(u)
103103
data["Code"] = code
104104
body, err := r.HTMLString("mail/auth/reset_passwd", data)
105105
if err != nil {
106106
log.Error("mail.SendResetPasswdMail(fail to render): %v", err)
107107
return
108108
}
109109

110-
msg := NewMailMessage([]string{user.Email}, subject, body)
111-
msg.Info = fmt.Sprintf("UID: %d, send reset password email", user.Id)
110+
msg := NewMailMessage([]string{u.Email}, subject, body)
111+
msg.Info = fmt.Sprintf("UID: %d, send reset password email", u.Id)
112112

113113
SendAsync(&msg)
114114
}
115115

116116
// SendIssueNotifyMail sends mail notification of all watchers of repository.
117-
func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
117+
func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
118118
ws, err := models.GetWatchers(repo.Id)
119119
if err != nil {
120120
return nil, errors.New("mail.NotifyWatchers(GetWatchers): " + err.Error())
@@ -123,7 +123,7 @@ func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issu
123123
tos := make([]string, 0, len(ws))
124124
for i := range ws {
125125
uid := ws[i].UserId
126-
if user.Id == uid {
126+
if u.Id == uid {
127127
continue
128128
}
129129
u, err := models.GetUserById(uid)
@@ -141,14 +141,14 @@ func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issu
141141
content := fmt.Sprintf("%s<br>-<br> <a href=\"%s%s/%s/issues/%d\">View it on Gogs</a>.",
142142
base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name),
143143
setting.AppUrl, owner.Name, repo.Name, issue.Index)
144-
msg := NewMailMessageFrom(tos, user.Email, subject, content)
144+
msg := NewMailMessageFrom(tos, u.Email, subject, content)
145145
msg.Info = fmt.Sprintf("Subject: %s, send issue notify emails", subject)
146146
SendAsync(&msg)
147147
return tos, nil
148148
}
149149

150150
// SendIssueMentionMail sends mail notification for who are mentioned in issue.
151-
func SendIssueMentionMail(r *middleware.Render, user, owner *models.User,
151+
func SendIssueMentionMail(r *middleware.Render, u, owner *models.User,
152152
repo *models.Repository, issue *models.Issue, tos []string) error {
153153

154154
if len(tos) == 0 {
@@ -166,14 +166,14 @@ func SendIssueMentionMail(r *middleware.Render, user, owner *models.User,
166166
return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err)
167167
}
168168

169-
msg := NewMailMessageFrom(tos, user.Email, subject, body)
169+
msg := NewMailMessageFrom(tos, u.Email, subject, body)
170170
msg.Info = fmt.Sprintf("Subject: %s, send issue mention emails", subject)
171171
SendAsync(&msg)
172172
return nil
173173
}
174174

175175
// SendCollaboratorMail sends mail notification to new collaborator.
176-
func SendCollaboratorMail(r *middleware.Render, user, owner *models.User,
176+
func SendCollaboratorMail(r *middleware.Render, u, owner *models.User,
177177
repo *models.Repository) error {
178178

179179
subject := fmt.Sprintf("%s added you to %s", owner.Name, repo.Name)
@@ -187,8 +187,8 @@ func SendCollaboratorMail(r *middleware.Render, user, owner *models.User,
187187
return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err)
188188
}
189189

190-
msg := NewMailMessage([]string{user.Email}, subject, body)
191-
msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id)
190+
msg := NewMailMessage([]string{u.Email}, subject, body)
191+
msg.Info = fmt.Sprintf("UID: %d, send register mail", u.Id)
192192

193193
SendAsync(&msg)
194194
return nil

0 commit comments

Comments
 (0)