Skip to content

Commit

Permalink
Run "make fmt" with go-1.6 (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
strk authored and lunny committed Mar 21, 2017
1 parent 888dee3 commit f73e734
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 67 deletions.
6 changes: 3 additions & 3 deletions integrations/signup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions models/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})

}
7 changes: 3 additions & 4 deletions models/migrations/v23.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (

// UserOpenID is the list of all OpenID identities of a user.
type UserOpenID struct {
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX NOT NULL"`
URI string `xorm:"UNIQUE NOT NULL"`
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX NOT NULL"`
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)
Expand Down
2 changes: 1 addition & 1 deletion models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion models/user_follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ func UnfollowUser(userID, followID int64) (err error) {
}
return sess.Commit()
}

9 changes: 4 additions & 5 deletions models/user_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ var (

// UserOpenID is the list of all OpenID identities of a user.
type UserOpenID struct {
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX NOT NULL"`
URI string `xorm:"UNIQUE NOT NULL"`
Show bool `xorm:"DEFAULT false"`
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX NOT NULL"`
URI string `xorm:"UNIQUE NOT NULL"`
Show bool `xorm:"DEFAULT false"`
}

// GetUserOpenIDs returns all openid addresses that belongs to given user.
Expand Down Expand Up @@ -122,4 +122,3 @@ func GetUserByOpenID(uri string) (*User, error) {

return nil, ErrUserNotExist{0, uri, 0}
}

8 changes: 4 additions & 4 deletions models/user_openid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions modules/auth/openid/discovery_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type timedDiscoveredInfo struct {

type timedDiscoveryCache struct {
cache map[string]timedDiscoveredInfo
ttl time.Duration
ttl time.Duration
mutex *sync.Mutex
}

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

5 changes: 3 additions & 2 deletions modules/auth/openid/discovery_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"time"
)

type testDiscoveredInfo struct {}
type testDiscoveredInfo struct{}

func (s *testDiscoveredInfo) ClaimedID() string {
return "claimedID"
}
Expand All @@ -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"})
Expand Down
4 changes: 1 addition & 3 deletions modules/auth/openid/openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

2 changes: 1 addition & 1 deletion modules/auth/user_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors)

// AddOpenIDForm is for changing openid uri
type AddOpenIDForm struct {
Openid string `binding:"Required;MaxSize(256)"`
Openid string `binding:"Required;MaxSize(256)"`
}

// Validate validates the fields
Expand Down
4 changes: 1 addition & 3 deletions modules/auth/user_form_auth_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"gopkg.in/macaron.v1"
)


// SignInOpenIDForm form for signing in with OpenID
type SignInOpenIDForm struct {
Openid string `binding:"Required;MaxSize(256)"`
Openid string `binding:"Required;MaxSize(256)"`
Remember bool
}

Expand Down Expand Up @@ -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)
}

4 changes: 2 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 22 additions & 19 deletions routers/user/auth_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,24 @@ 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 {
if err != nil {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
return;
}
return
}

// Request optional nickname and email info
// NOTE: change to `openid.sreg.required` to require it
Expand All @@ -134,10 +135,10 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
// signInOpenIDVerify handles response from OpenID provider
func signInOpenIDVerify(ctx *context.Context) {

log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())

fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
log.Trace("Full URL: " + fullURL)
fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
log.Trace("Full URL: " + fullURL)

var id, err = openid.Verify(fullURL)
if err != nil {
Expand All @@ -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,
})
Expand Down Expand Up @@ -188,12 +189,12 @@ func signInOpenIDVerify(ctx *context.Context) {
email := values.Get("openid.sreg.email")
nickname := values.Get("openid.sreg.nickname")

log.Trace("User has email=" + email + " and nickname=" + nickname)
log.Trace("User has email=" + email + " and nickname=" + nickname)

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,
})
Expand All @@ -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,
})
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit f73e734

Please sign in to comment.