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

release/v1.15
Sandro Santilli 2017-03-21 01:55:00 +01:00 committed by Lunny Xiao
parent 888dee3b5f
commit f73e734411
15 changed files with 62 additions and 67 deletions

View File

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

View File

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

View File

@ -17,7 +17,6 @@ type UserOpenID struct {
URI string `xorm:"UNIQUE NOT NULL"`
}
func addUserOpenID(x *xorm.Engine) error {
if err := x.Sync2(new(UserOpenID)); err != nil {
return fmt.Errorf("Sync2: %v", err)

View File

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

View File

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

View File

@ -122,4 +122,3 @@ func GetUserByOpenID(uri string) (*User, error) {
return nil, ErrUserNotExist{0, uri, 0}
}

View File

@ -52,14 +52,14 @@ func TestGetUserByOpenID(t *testing.T) {
func TestToggleUserOpenIDVisibility(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
oids, err := GetUserOpenIDs(int64(2))
if ! assert.NoError(t, err) {
if !assert.NoError(t, err) {
return
}
assert.Len(t, oids, 1)
assert.True(t, oids[0].Show)
err = ToggleUserOpenIDVisibility(oids[0].ID)
if ! assert.NoError(t, err) {
if !assert.NoError(t, err) {
return
}
@ -69,12 +69,12 @@ func TestToggleUserOpenIDVisibility(t *testing.T) {
assert.False(t, oids[0].Show)
}
err = ToggleUserOpenIDVisibility(oids[0].ID)
if ! assert.NoError(t, err) {
if !assert.NoError(t, err) {
return
}
oids, err = GetUserOpenIDs(int64(2))
if ! assert.NoError(t, err) {
if !assert.NoError(t, err) {
return
}
assert.Len(t, oids, 1)

View File

@ -56,4 +56,3 @@ func (s *timedDiscoveryCache) Get(id string) openid.DiscoveredInfo {
}
return nil
}

View File

@ -9,7 +9,8 @@ import (
"time"
)
type testDiscoveredInfo struct {}
type testDiscoveredInfo struct{}
func (s *testDiscoveredInfo) ClaimedID() string {
return "claimedID"
}
@ -21,7 +22,7 @@ func (s *testDiscoveredInfo) OpLocalID() string {
}
func TestTimedDiscoveryCache(t *testing.T) {
dc := newTimedDiscoveryCache(1*time.Second)
dc := newTimedDiscoveryCache(1 * time.Second)
// Put some initial values
dc.Put("foo", &testDiscoveredInfo{}) //openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})

View File

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

View File

@ -9,7 +9,6 @@ import (
"gopkg.in/macaron.v1"
)
// SignInOpenIDForm form for signing in with OpenID
type SignInOpenIDForm struct {
Openid string `binding:"Required;MaxSize(256)"`
@ -42,4 +41,3 @@ type ConnectOpenIDForm struct {
func (f *ConnectOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}

View File

@ -762,14 +762,14 @@ please consider changing to GITEA_CUSTOM`)
EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(true)
pats := sec.Key("WHITELISTED_URIS").Strings(" ")
if ( len(pats) != 0 ) {
if len(pats) != 0 {
OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
for i, p := range pats {
OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
}
}
pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
if ( len(pats) != 0 ) {
if len(pats) != 0 {
OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
for i, p := range pats {
OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)

View File

@ -102,22 +102,23 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
id, err := openid.Normalize(form.Openid)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
return;
return
}
form.Openid = id
log.Trace("OpenID uri: " + id)
err = allowedOpenIDURI(id); if err != nil {
err = allowedOpenIDURI(id)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
return;
return
}
redirectTo := setting.AppURL + "user/login/openid"
url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
return;
return
}
// Request optional nickname and email info
@ -154,7 +155,7 @@ func signInOpenIDVerify(ctx *context.Context) {
u, _ := models.GetUserByOpenID(id)
if err != nil {
if ! models.IsErrUserNotExist(err) {
if !models.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
Openid: id,
})
@ -193,7 +194,7 @@ func signInOpenIDVerify(ctx *context.Context) {
if email != "" {
u, _ = models.GetUserByEmail(email)
if err != nil {
if ! models.IsErrUserNotExist(err) {
if !models.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
Openid: id,
})
@ -208,7 +209,7 @@ func signInOpenIDVerify(ctx *context.Context) {
if u == nil && nickname != "" {
u, _ = models.GetUserByName(nickname)
if err != nil {
if ! models.IsErrUserNotExist(err) {
if !models.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
Openid: id,
})
@ -230,7 +231,7 @@ func signInOpenIDVerify(ctx *context.Context) {
ctx.Session.Set("openid_determined_username", nickname)
if u != nil || ! setting.EnableOpenIDSignUp {
if u != nil || !setting.EnableOpenIDSignUp {
ctx.Redirect(setting.AppSubURL + "/user/openid/connect")
} else {
ctx.Redirect(setting.AppSubURL + "/user/openid/register")
@ -280,7 +281,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
}
// add OpenID for the user
userOID := &models.UserOpenID{UID:u.ID, URI:oid}
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
if err = models.AddUserOpenID(userOID); err != nil {
if models.IsErrOpenIDAlreadyUsed(err) {
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
@ -299,7 +300,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
// RegisterOpenID shows a form to create a new user authenticated via an OpenID URI
func RegisterOpenID(ctx *context.Context) {
if ! setting.EnableOpenIDSignUp {
if !setting.EnableOpenIDSignUp {
ctx.Error(403)
return
}
@ -327,7 +328,7 @@ func RegisterOpenID(ctx *context.Context) {
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
if ! setting.EnableOpenIDSignUp {
if !setting.EnableOpenIDSignUp {
ctx.Error(403)
return
}
@ -351,7 +352,9 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
}
len := setting.MinPasswordLength
if len < 256 { len = 256 }
if len < 256 {
len = 256
}
password, err := base.GetRandomString(len)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSignUpOID, form)
@ -387,7 +390,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
log.Trace("Account created: %s", u.Name)
// add OpenID for the user
userOID := &models.UserOpenID{UID:u.ID, URI:oid}
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
if err = models.AddUserOpenID(userOID); err != nil {
if models.IsErrOpenIDAlreadyUsed(err) {
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)

View File

@ -5,7 +5,6 @@
package user
import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/auth/openid"
@ -64,7 +63,7 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
id, err := openid.Normalize(form.Openid)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
return;
return
}
form.Openid = id
log.Trace("Normalized id: " + id)
@ -84,12 +83,11 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
}
}
redirectTo := setting.AppURL + "user/settings/openid"
url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
if err != nil {
ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
return;
return
}
ctx.Redirect(url)
}
@ -117,10 +115,10 @@ func settingsOpenIDVerify(ctx *context.Context) {
log.Trace("Verified ID: " + id)
oid := &models.UserOpenID{UID:ctx.User.ID, URI:id}
oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
if err = models.AddUserOpenID(oid); err != nil {
if models.IsErrOpenIDAlreadyUsed(err) {
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{ Openid: id })
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{Openid: id})
return
}
ctx.Handle(500, "AddUserOpenID", err)
@ -155,4 +153,3 @@ func ToggleOpenIDVisibility(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/openid")
}