Browse Source

Run "make fmt" with go-1.6 (#1333)

Sandro Santilli 3 years ago
parent
commit
f73e734411

+ 3 - 3
integrations/signup_test.go

@@ -12,9 +12,9 @@ import (
12 12
 )
13 13
 
14 14
 var signupFormSample map[string][]string = map[string][]string{
15
-	"Name":   []string{"tester"},
16
-	"Email":  []string{"user1@example.com"},
17
-	"Passwd": []string{"12345678"},
15
+	"Name":   {"tester"},
16
+	"Email":  {"user1@example.com"},
17
+	"Passwd": {"12345678"},
18 18
 }
19 19
 
20 20
 func signup(t *utils.T) error {

+ 5 - 3
models/issue_test.go

@@ -67,8 +67,10 @@ func TestGetParticipantsByIssueID(t *testing.T) {
67 67
 	checkPartecipants := func(issueID int64, userIDs []int) {
68 68
 		partecipants, err := GetParticipantsByIssueID(issueID)
69 69
 		if assert.NoError(t, err) {
70
-			partecipantsIDs := make([]int,len(partecipants))
71
-			for i,u := range partecipants { partecipantsIDs[i] = int(u.ID) }
70
+			partecipantsIDs := make([]int, len(partecipants))
71
+			for i, u := range partecipants {
72
+				partecipantsIDs[i] = int(u.ID)
73
+			}
72 74
 			sort.Ints(partecipantsIDs)
73 75
 			sort.Ints(userIDs)
74 76
 			assert.Equal(t, userIDs, partecipantsIDs)
@@ -79,6 +81,6 @@ func TestGetParticipantsByIssueID(t *testing.T) {
79 81
 	// User 1 is issue1 poster (see fixtures/issue.yml)
80 82
 	// User 2 only labeled issue1 (see fixtures/comment.yml)
81 83
 	// Users 3 and 5 made actual comments (see fixtures/comment.yml)
82
-	checkPartecipants(1, []int{3,5})
84
+	checkPartecipants(1, []int{3, 5})
83 85
 
84 86
 }

+ 3 - 4
models/migrations/v23.go

@@ -12,12 +12,11 @@ import (
12 12
 
13 13
 // UserOpenID is the list of all OpenID identities of a user.
14 14
 type UserOpenID struct {
15
-	ID          int64  `xorm:"pk autoincr"`
16
-	UID         int64  `xorm:"INDEX NOT NULL"`
17
-	URI         string `xorm:"UNIQUE NOT NULL"`
15
+	ID  int64  `xorm:"pk autoincr"`
16
+	UID int64  `xorm:"INDEX NOT NULL"`
17
+	URI string `xorm:"UNIQUE NOT NULL"`
18 18
 }
19 19
 
20
-
21 20
 func addUserOpenID(x *xorm.Engine) error {
22 21
 	if err := x.Sync2(new(UserOpenID)); err != nil {
23 22
 		return fmt.Errorf("Sync2: %v", err)

+ 1 - 1
models/org_team.go

@@ -143,7 +143,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
143 143
 	if err != nil {
144 144
 		return fmt.Errorf("getTeamUsersByTeamID: %v", err)
145 145
 	}
146
-	for _, teamUser:= range teamUsers {
146
+	for _, teamUser := range teamUsers {
147 147
 		has, err := hasAccess(e, teamUser.UID, repo, AccessModeRead)
148 148
 		if err != nil {
149 149
 			return err

+ 0 - 1
models/user_follow.go

@@ -68,4 +68,3 @@ func UnfollowUser(userID, followID int64) (err error) {
68 68
 	}
69 69
 	return sess.Commit()
70 70
 }
71
-

+ 4 - 5
models/user_openid.go

@@ -18,10 +18,10 @@ var (
18 18
 
19 19
 // UserOpenID is the list of all OpenID identities of a user.
20 20
 type UserOpenID struct {
21
-	ID          int64  `xorm:"pk autoincr"`
22
-	UID         int64  `xorm:"INDEX NOT NULL"`
23
-	URI         string `xorm:"UNIQUE NOT NULL"`
24
-	Show        bool   `xorm:"DEFAULT false"`
21
+	ID   int64  `xorm:"pk autoincr"`
22
+	UID  int64  `xorm:"INDEX NOT NULL"`
23
+	URI  string `xorm:"UNIQUE NOT NULL"`
24
+	Show bool   `xorm:"DEFAULT false"`
25 25
 }
26 26
 
27 27
 // GetUserOpenIDs returns all openid addresses that belongs to given user.
@@ -122,4 +122,3 @@ func GetUserByOpenID(uri string) (*User, error) {
122 122
 
123 123
 	return nil, ErrUserNotExist{0, uri, 0}
124 124
 }
125
-

+ 4 - 4
models/user_openid_test.go

@@ -52,14 +52,14 @@ func TestGetUserByOpenID(t *testing.T) {
52 52
 func TestToggleUserOpenIDVisibility(t *testing.T) {
53 53
 	assert.NoError(t, PrepareTestDatabase())
54 54
 	oids, err := GetUserOpenIDs(int64(2))
55
-	if ! assert.NoError(t, err) {
55
+	if !assert.NoError(t, err) {
56 56
 		return
57 57
 	}
58 58
 	assert.Len(t, oids, 1)
59 59
 	assert.True(t, oids[0].Show)
60 60
 
61 61
 	err = ToggleUserOpenIDVisibility(oids[0].ID)
62
-	if ! assert.NoError(t, err) {
62
+	if !assert.NoError(t, err) {
63 63
 		return
64 64
 	}
65 65
 
@@ -69,12 +69,12 @@ func TestToggleUserOpenIDVisibility(t *testing.T) {
69 69
 		assert.False(t, oids[0].Show)
70 70
 	}
71 71
 	err = ToggleUserOpenIDVisibility(oids[0].ID)
72
-	if ! assert.NoError(t, err) {
72
+	if !assert.NoError(t, err) {
73 73
 		return
74 74
 	}
75 75
 
76 76
 	oids, err = GetUserOpenIDs(int64(2))
77
-	if ! assert.NoError(t, err) {
77
+	if !assert.NoError(t, err) {
78 78
 		return
79 79
 	}
80 80
 	assert.Len(t, oids, 1)

+ 1 - 2
modules/auth/openid/discovery_cache.go

@@ -18,7 +18,7 @@ type timedDiscoveredInfo struct {
18 18
 
19 19
 type timedDiscoveryCache struct {
20 20
 	cache map[string]timedDiscoveredInfo
21
-	ttl time.Duration
21
+	ttl   time.Duration
22 22
 	mutex *sync.Mutex
23 23
 }
24 24
 
@@ -56,4 +56,3 @@ func (s *timedDiscoveryCache) Get(id string) openid.DiscoveredInfo {
56 56
 	}
57 57
 	return nil
58 58
 }
59
-

+ 3 - 2
modules/auth/openid/discovery_cache_test.go

@@ -9,7 +9,8 @@ import (
9 9
 	"time"
10 10
 )
11 11
 
12
-type testDiscoveredInfo struct {}
12
+type testDiscoveredInfo struct{}
13
+
13 14
 func (s *testDiscoveredInfo) ClaimedID() string {
14 15
 	return "claimedID"
15 16
 }
@@ -21,7 +22,7 @@ func (s *testDiscoveredInfo) OpLocalID() string {
21 22
 }
22 23
 
23 24
 func TestTimedDiscoveryCache(t *testing.T) {
24
-	dc := newTimedDiscoveryCache(1*time.Second)
25
+	dc := newTimedDiscoveryCache(1 * time.Second)
25 26
 
26 27
 	// Put some initial values
27 28
 	dc.Put("foo", &testDiscoveredInfo{}) //openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})

+ 1 - 3
modules/auth/openid/openid.go

@@ -17,8 +17,7 @@ import (
17 17
 // least
18 18
 // the nonceStore between them.
19 19
 var nonceStore = openid.NewSimpleNonceStore()
20
-var discoveryCache = newTimedDiscoveryCache(24*time.Hour)
21
-
20
+var discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
22 21
 
23 22
 // Verify handles response from OpenID provider
24 23
 func Verify(fullURL string) (id string, err error) {
@@ -34,4 +33,3 @@ func Normalize(url string) (id string, err error) {
34 33
 func RedirectURL(id, callbackURL, realm string) (string, error) {
35 34
 	return openid.RedirectURL(id, callbackURL, realm)
36 35
 }
37
-

+ 1 - 1
modules/auth/user_form.go

@@ -155,7 +155,7 @@ func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors)
155 155
 
156 156
 // AddOpenIDForm is for changing openid uri
157 157
 type AddOpenIDForm struct {
158
-	Openid      string `binding:"Required;MaxSize(256)"`
158
+	Openid string `binding:"Required;MaxSize(256)"`
159 159
 }
160 160
 
161 161
 // Validate validates the fields

+ 1 - 3
modules/auth/user_form_auth_openid.go

@@ -9,10 +9,9 @@ import (
9 9
 	"gopkg.in/macaron.v1"
10 10
 )
11 11
 
12
-
13 12
 // SignInOpenIDForm form for signing in with OpenID
14 13
 type SignInOpenIDForm struct {
15
-	Openid string `binding:"Required;MaxSize(256)"`
14
+	Openid   string `binding:"Required;MaxSize(256)"`
16 15
 	Remember bool
17 16
 }
18 17
 
@@ -42,4 +41,3 @@ type ConnectOpenIDForm struct {
42 41
 func (f *ConnectOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
43 42
 	return validate(errs, ctx.Data, f, ctx.Locale)
44 43
 }
45
-

+ 2 - 2
modules/setting/setting.go

@@ -762,14 +762,14 @@ please consider changing to GITEA_CUSTOM`)
762 762
 	EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
763 763
 	EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(true)
764 764
 	pats := sec.Key("WHITELISTED_URIS").Strings(" ")
765
-	if ( len(pats) != 0 ) {
765
+	if len(pats) != 0 {
766 766
 		OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
767 767
 		for i, p := range pats {
768 768
 			OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
769 769
 		}
770 770
 	}
771 771
 	pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
772
-	if ( len(pats) != 0 ) {
772
+	if len(pats) != 0 {
773 773
 		OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
774 774
 		for i, p := range pats {
775 775
 			OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)

+ 22 - 19
routers/user/auth_openid.go

@@ -102,23 +102,24 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
102 102
 	id, err := openid.Normalize(form.Openid)
103 103
 	if err != nil {
104 104
 		ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
105
-                return;
105
+		return
106 106
 	}
107 107
 	form.Openid = id
108 108
 
109 109
 	log.Trace("OpenID uri: " + id)
110 110
 
111
-	err = allowedOpenIDURI(id); if err != nil {
111
+	err = allowedOpenIDURI(id)
112
+	if err != nil {
112 113
 		ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
113
-                return;
114
+		return
114 115
 	}
115 116
 
116 117
 	redirectTo := setting.AppURL + "user/login/openid"
117 118
 	url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
118
-        if err != nil {
119
+	if err != nil {
119 120
 		ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
120
-                return;
121
-        }
121
+		return
122
+	}
122 123
 
123 124
 	// Request optional nickname and email info
124 125
 	// NOTE: change to `openid.sreg.required` to require it
@@ -134,10 +135,10 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
134 135
 // signInOpenIDVerify handles response from OpenID provider
135 136
 func signInOpenIDVerify(ctx *context.Context) {
136 137
 
137
-        log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
138
+	log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
138 139
 
139
-        fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
140
-        log.Trace("Full URL: " + fullURL)
140
+	fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
141
+	log.Trace("Full URL: " + fullURL)
141 142
 
142 143
 	var id, err = openid.Verify(fullURL)
143 144
 	if err != nil {
@@ -154,7 +155,7 @@ func signInOpenIDVerify(ctx *context.Context) {
154 155
 
155 156
 	u, _ := models.GetUserByOpenID(id)
156 157
 	if err != nil {
157
-		if ! models.IsErrUserNotExist(err) {
158
+		if !models.IsErrUserNotExist(err) {
158 159
 			ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
159 160
 				Openid: id,
160 161
 			})
@@ -188,12 +189,12 @@ func signInOpenIDVerify(ctx *context.Context) {
188 189
 	email := values.Get("openid.sreg.email")
189 190
 	nickname := values.Get("openid.sreg.nickname")
190 191
 
191
-	log.Trace("User has email=" + email +  " and nickname=" + nickname)
192
+	log.Trace("User has email=" + email + " and nickname=" + nickname)
192 193
 
193 194
 	if email != "" {
194 195
 		u, _ = models.GetUserByEmail(email)
195 196
 		if err != nil {
196
-			if ! models.IsErrUserNotExist(err) {
197
+			if !models.IsErrUserNotExist(err) {
197 198
 				ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
198 199
 					Openid: id,
199 200
 				})
@@ -208,7 +209,7 @@ func signInOpenIDVerify(ctx *context.Context) {
208 209
 	if u == nil && nickname != "" {
209 210
 		u, _ = models.GetUserByName(nickname)
210 211
 		if err != nil {
211
-			if ! models.IsErrUserNotExist(err) {
212
+			if !models.IsErrUserNotExist(err) {
212 213
 				ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
213 214
 					Openid: id,
214 215
 				})
@@ -230,7 +231,7 @@ func signInOpenIDVerify(ctx *context.Context) {
230 231
 
231 232
 	ctx.Session.Set("openid_determined_username", nickname)
232 233
 
233
-	if u != nil || ! setting.EnableOpenIDSignUp {
234
+	if u != nil || !setting.EnableOpenIDSignUp {
234 235
 		ctx.Redirect(setting.AppSubURL + "/user/openid/connect")
235 236
 	} else {
236 237
 		ctx.Redirect(setting.AppSubURL + "/user/openid/register")
@@ -280,7 +281,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
280 281
 	}
281 282
 
282 283
 	// add OpenID for the user
283
-	userOID := &models.UserOpenID{UID:u.ID, URI:oid}
284
+	userOID := &models.UserOpenID{UID: u.ID, URI: oid}
284 285
 	if err = models.AddUserOpenID(userOID); err != nil {
285 286
 		if models.IsErrOpenIDAlreadyUsed(err) {
286 287
 			ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
@@ -299,7 +300,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
299 300
 
300 301
 // RegisterOpenID shows a form to create a new user authenticated via an OpenID URI
301 302
 func RegisterOpenID(ctx *context.Context) {
302
-	if ! setting.EnableOpenIDSignUp {
303
+	if !setting.EnableOpenIDSignUp {
303 304
 		ctx.Error(403)
304 305
 		return
305 306
 	}
@@ -327,7 +328,7 @@ func RegisterOpenID(ctx *context.Context) {
327 328
 
328 329
 // RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
329 330
 func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
330
-	if ! setting.EnableOpenIDSignUp {
331
+	if !setting.EnableOpenIDSignUp {
331 332
 		ctx.Error(403)
332 333
 		return
333 334
 	}
@@ -351,7 +352,9 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
351 352
 	}
352 353
 
353 354
 	len := setting.MinPasswordLength
354
-	if len < 256 { len = 256 }
355
+	if len < 256 {
356
+		len = 256
357
+	}
355 358
 	password, err := base.GetRandomString(len)
356 359
 	if err != nil {
357 360
 		ctx.RenderWithErr(err.Error(), tplSignUpOID, form)
@@ -387,7 +390,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
387 390
 	log.Trace("Account created: %s", u.Name)
388 391
 
389 392
 	// add OpenID for the user
390
-	userOID := &models.UserOpenID{UID:u.ID, URI:oid}
393
+	userOID := &models.UserOpenID{UID: u.ID, URI: oid}
391 394
 	if err = models.AddUserOpenID(userOID); err != nil {
392 395
 		if models.IsErrOpenIDAlreadyUsed(err) {
393 396
 			ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)

+ 11 - 14
routers/user/setting_openid.go

@@ -5,7 +5,6 @@
5 5
 package user
6 6
 
7 7
 import (
8
-
9 8
 	"code.gitea.io/gitea/models"
10 9
 	"code.gitea.io/gitea/modules/auth"
11 10
 	"code.gitea.io/gitea/modules/auth/openid"
@@ -16,7 +15,7 @@ import (
16 15
 )
17 16
 
18 17
 const (
19
-	tplSettingsOpenID       base.TplName = "user/settings/openid"
18
+	tplSettingsOpenID base.TplName = "user/settings/openid"
20 19
 )
21 20
 
22 21
 // SettingsOpenID renders change user's openid page
@@ -64,10 +63,10 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
64 63
 	id, err := openid.Normalize(form.Openid)
65 64
 	if err != nil {
66 65
 		ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
67
-		return;
66
+		return
68 67
 	}
69 68
 	form.Openid = id
70
-        log.Trace("Normalized id: " + id)
69
+	log.Trace("Normalized id: " + id)
71 70
 
72 71
 	oids, err := models.GetUserOpenIDs(ctx.User.ID)
73 72
 	if err != nil {
@@ -84,21 +83,20 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
84 83
 		}
85 84
 	}
86 85
 
87
-
88 86
 	redirectTo := setting.AppURL + "user/settings/openid"
89 87
 	url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
90
-        if err != nil {
88
+	if err != nil {
91 89
 		ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
92
-                return;
93
-        }
90
+		return
91
+	}
94 92
 	ctx.Redirect(url)
95 93
 }
96 94
 
97 95
 func settingsOpenIDVerify(ctx *context.Context) {
98
-        log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
96
+	log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
99 97
 
100
-        fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
101
-        log.Trace("Full URL: " + fullURL)
98
+	fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
99
+	log.Trace("Full URL: " + fullURL)
102 100
 
103 101
 	oids, err := models.GetUserOpenIDs(ctx.User.ID)
104 102
 	if err != nil {
@@ -117,10 +115,10 @@ func settingsOpenIDVerify(ctx *context.Context) {
117 115
 
118 116
 	log.Trace("Verified ID: " + id)
119 117
 
120
-	oid := &models.UserOpenID{UID:ctx.User.ID, URI:id}
118
+	oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
121 119
 	if err = models.AddUserOpenID(oid); err != nil {
122 120
 		if models.IsErrOpenIDAlreadyUsed(err) {
123
-			ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{ Openid: id })
121
+			ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{Openid: id})
124 122
 			return
125 123
 		}
126 124
 		ctx.Handle(500, "AddUserOpenID", err)
@@ -155,4 +153,3 @@ func ToggleOpenIDVisibility(ctx *context.Context) {
155 153
 
156 154
 	ctx.Redirect(setting.AppSubURL + "/user/settings/openid")
157 155
 }
158
-