aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/cmd/cmd.go2
-rw-r--r--internal/context/repo.go6
-rw-r--r--internal/db/git_diff_test.go26
-rw-r--r--internal/db/issue.go8
-rw-r--r--internal/db/login_source.go14
-rw-r--r--internal/db/mirror.go2
-rw-r--r--internal/db/org_team.go4
-rw-r--r--internal/db/repo.go16
-rw-r--r--internal/db/repo_branch.go4
-rw-r--r--internal/db/repo_editor.go4
-rw-r--r--internal/db/token.go2
-rw-r--r--internal/db/two_factor.go4
-rw-r--r--internal/db/user.go14
-rw-r--r--internal/db/user_mail.go6
-rw-r--r--internal/db/webhook.go4
-rw-r--r--internal/email/message.go18
-rw-r--r--internal/form/repo.go8
-rw-r--r--internal/httplib/httplib.go2
-rw-r--r--internal/route/api/v1/repo/repo.go10
-rw-r--r--internal/route/api/v1/user/app.go4
-rw-r--r--internal/route/repo/issue.go3
-rw-r--r--internal/route/user/auth.go5
-rw-r--r--internal/template/template.go32
-rw-r--r--internal/tool/file.go20
-rw-r--r--internal/tool/tool.go30
25 files changed, 91 insertions, 157 deletions
diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go
index 29afa625..7dc2d5c5 100644
--- a/internal/cmd/cmd.go
+++ b/internal/cmd/cmd.go
@@ -25,6 +25,7 @@ func boolFlag(name, usage string) cli.BoolFlag {
}
}
+//nolint:deadcode
func intFlag(name string, value int, usage string) cli.IntFlag {
return cli.IntFlag{
Name: name,
@@ -33,6 +34,7 @@ func intFlag(name string, value int, usage string) cli.IntFlag {
}
}
+//nolint:deadcode
func durationFlag(name string, value time.Duration, usage string) cli.DurationFlag {
return cli.DurationFlag{
Name: name,
diff --git a/internal/context/repo.go b/internal/context/repo.go
index 7d030458..31729f9e 100644
--- a/internal/context/repo.go
+++ b/internal/context/repo.go
@@ -15,9 +15,9 @@ import (
"github.com/gogs/git-module"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
- "gogs.io/gogs/internal/conf"
)
type PullRequest struct {
@@ -142,10 +142,6 @@ func RepoAssignment(pages ...bool) macaron.Handler {
ownerName := c.Params(":username")
repoName := strings.TrimSuffix(c.Params(":reponame"), ".git")
- refName := c.Params(":branchname")
- if len(refName) == 0 {
- refName = c.Params(":path")
- }
// Check if the user is the same as the repository owner
if c.IsLogged && c.User.LowerName == strings.ToLower(ownerName) {
diff --git a/internal/db/git_diff_test.go b/internal/db/git_diff_test.go
index d92afe9e..697e8dc7 100644
--- a/internal/db/git_diff_test.go
+++ b/internal/db/git_diff_test.go
@@ -18,24 +18,18 @@ func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
}
}
-func assertLineEqual(t *testing.T, d1 *git.DiffLine, d2 *git.DiffLine) {
- if d1 != d2 {
- t.Errorf("%v should be equal %v", d1, d2)
- }
-}
-
func Test_diffToHTML(t *testing.T) {
assertEqual(t, "+foo <span class=\"added-code\">bar</span> biz", diffToHTML([]dmp.Diff{
- dmp.Diff{dmp.DiffEqual, "foo "},
- dmp.Diff{dmp.DiffInsert, "bar"},
- dmp.Diff{dmp.DiffDelete, " baz"},
- dmp.Diff{dmp.DiffEqual, " biz"},
- }, git.DIFF_LINE_ADD))
+ {Type: dmp.DiffEqual, Text: "foo "},
+ {Type: dmp.DiffInsert, Text: "bar"},
+ {Type: dmp.DiffDelete, Text: " baz"},
+ {Type: dmp.DiffEqual, Text: " biz"},
+ }, git.DiffLineAdd))
assertEqual(t, "-foo <span class=\"removed-code\">bar</span> biz", diffToHTML([]dmp.Diff{
- dmp.Diff{dmp.DiffEqual, "foo "},
- dmp.Diff{dmp.DiffDelete, "bar"},
- dmp.Diff{dmp.DiffInsert, " baz"},
- dmp.Diff{dmp.DiffEqual, " biz"},
- }, git.DIFF_LINE_DEL))
+ {Type: dmp.DiffEqual, Text: "foo "},
+ {Type: dmp.DiffDelete, Text: "bar"},
+ {Type: dmp.DiffInsert, Text: " baz"},
+ {Type: dmp.DiffEqual, Text: " biz"},
+ }, git.DiffLineDel))
}
diff --git a/internal/db/issue.go b/internal/db/issue.go
index 092395d8..93915244 100644
--- a/internal/db/issue.go
+++ b/internal/db/issue.go
@@ -15,8 +15,8 @@ import (
api "github.com/gogs/go-gogs-client"
- "gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/tool"
)
@@ -801,7 +801,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
func GetIssueByRef(ref string) (*Issue, error) {
n := strings.IndexByte(ref, byte('#'))
if n == -1 {
- return nil, errors.InvalidIssueReference{ref}
+ return nil, errors.InvalidIssueReference{Ref: ref}
}
index := com.StrTo(ref[n+1:]).MustInt64()
@@ -832,7 +832,7 @@ func GetRawIssueByIndex(repoID, index int64) (*Issue, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.IssueNotExist{0, repoID, index}
+ return nil, errors.IssueNotExist{RepoID: repoID, Index: index}
}
return issue, nil
}
@@ -852,7 +852,7 @@ func getRawIssueByID(e Engine, id int64) (*Issue, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.IssueNotExist{id, 0, 0}
+ return nil, errors.IssueNotExist{ID: id}
}
return issue, nil
}
diff --git a/internal/db/login_source.go b/internal/db/login_source.go
index 22b53a62..cb261f32 100644
--- a/internal/db/login_source.go
+++ b/internal/db/login_source.go
@@ -439,7 +439,7 @@ func (s *LocalLoginSources) GetLoginSourceByID(id int64) (*LoginSource, error) {
}
}
- return nil, errors.LoginSourceNotExist{id}
+ return nil, errors.LoginSourceNotExist{ID: id}
}
// UpdateLoginSource updates in-memory copy of the authentication source.
@@ -556,7 +556,7 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR
username, fn, sn, mail, isAdmin, succeed := source.Cfg.(*LDAPConfig).SearchEntry(login, password, source.Type == LOGIN_DLDAP)
if !succeed {
// User not in LDAP, do nothing
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
}
if !autoRegister {
@@ -674,9 +674,9 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
if len(cfg.AllowedDomains) > 0 {
idx := strings.Index(login, "@")
if idx == -1 {
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) {
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
}
}
@@ -794,7 +794,7 @@ func LoginViaGitHub(user *User, login, password string, sourceID int64, cfg *Git
func remoteUserLogin(user *User, login, password string, source *LoginSource, autoRegister bool) (*User, error) {
if !source.IsActived {
- return nil, errors.LoginSourceNotActivated{source.ID}
+ return nil, errors.LoginSourceNotActivated{SourceID: source.ID}
}
switch source.Type {
@@ -808,7 +808,7 @@ func remoteUserLogin(user *User, login, password string, source *LoginSource, au
return LoginViaGitHub(user, login, password, source.ID, source.Cfg.(*GitHubConfig), autoRegister)
}
- return nil, errors.InvalidLoginSourceType{source.Type}
+ return nil, errors.InvalidLoginSourceType{Type: source.Type}
}
// UserLogin validates user name and password via given login source ID.
@@ -830,7 +830,7 @@ func UserLogin(username, password string, loginSourceID int64) (*User, error) {
// Note: This check is unnecessary but to reduce user confusion at login page
// and make it more consistent at user's perspective.
if loginSourceID >= 0 && user.LoginSource != loginSourceID {
- return nil, errors.LoginSourceMismatch{loginSourceID, user.LoginSource}
+ return nil, errors.LoginSourceMismatch{Expect: loginSourceID, Actual: user.LoginSource}
}
// Validate password hash fetched from database for local accounts
diff --git a/internal/db/mirror.go b/internal/db/mirror.go
index b85a62b2..dd767990 100644
--- a/internal/db/mirror.go
+++ b/internal/db/mirror.go
@@ -316,7 +316,7 @@ func getMirrorByRepoID(e Engine, repoID int64) (*Mirror, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.MirrorNotExist{repoID}
+ return nil, errors.MirrorNotExist{RepoID: repoID}
}
return m, nil
}
diff --git a/internal/db/org_team.go b/internal/db/org_team.go
index 7021e42d..accbfe5b 100644
--- a/internal/db/org_team.go
+++ b/internal/db/org_team.go
@@ -275,7 +275,7 @@ func getTeamOfOrgByName(e Engine, orgID int64, name string) (*Team, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TeamNotExist{0, name}
+ return nil, errors.TeamNotExist{Name: name}
}
return t, nil
}
@@ -291,7 +291,7 @@ func getTeamByID(e Engine, teamID int64) (*Team, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TeamNotExist{teamID, ""}
+ return nil, errors.TeamNotExist{TeamID: teamID}
}
return t, nil
}
diff --git a/internal/db/repo.go b/internal/db/repo.go
index e3d881d0..e28258e1 100644
--- a/internal/db/repo.go
+++ b/internal/db/repo.go
@@ -1106,7 +1106,7 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err
// CreateRepository creates a repository for given user or organization.
func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository, err error) {
if !owner.CanCreateRepo() {
- return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
+ return nil, errors.ReachLimitOfRepo{Limit: owner.RepoCreationNum()}
}
repo := &Repository{
@@ -1486,7 +1486,7 @@ func DeleteRepository(uid, repoID int64) error {
if err != nil {
return err
} else if !has {
- return errors.RepoNotExist{repoID, uid, ""}
+ return errors.RepoNotExist{ID: repoID, UserID: uid}
}
// In case is a organization.
@@ -1603,7 +1603,7 @@ func DeleteRepository(uid, repoID int64) error {
func GetRepositoryByRef(ref string) (*Repository, error) {
n := strings.IndexByte(ref, byte('/'))
if n < 2 {
- return nil, errors.InvalidRepoReference{ref}
+ return nil, errors.InvalidRepoReference{Ref: ref}
}
userName, repoName := ref[:n], ref[n+1:]
@@ -1625,7 +1625,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.RepoNotExist{0, ownerID, name}
+ return nil, errors.RepoNotExist{UserID: ownerID, Name: name}
}
return repo, repo.LoadAttributes()
}
@@ -1636,7 +1636,7 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.RepoNotExist{id, 0, ""}
+ return nil, errors.RepoNotExist{ID: id}
}
return repo, repo.loadAttributes(e)
}
@@ -2356,7 +2356,7 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
// ForkRepository creates a fork of target repository under another user domain.
func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string) (_ *Repository, err error) {
if !owner.CanCreateRepo() {
- return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
+ return nil, errors.ReachLimitOfRepo{Limit: owner.RepoCreationNum()}
}
repo := &Repository{
@@ -2390,14 +2390,14 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
fmt.Sprintf("ForkRepository 'git clone': %s/%s", owner.Name, repo.Name),
"git", "clone", "--bare", baseRepo.RepoPath(), repoPath)
if err != nil {
- return nil, fmt.Errorf("git clone: %v", stderr)
+ return nil, fmt.Errorf("git clone: %v - %s", err, stderr)
}
_, stderr, err = process.ExecDir(-1,
repoPath, fmt.Sprintf("ForkRepository 'git update-server-info': %s", repoPath),
"git", "update-server-info")
if err != nil {
- return nil, fmt.Errorf("git update-server-info: %v", err)
+ return nil, fmt.Errorf("git update-server-info: %v - %s", err, stderr)
}
if err = createDelegateHooks(repoPath); err != nil {
diff --git a/internal/db/repo_branch.go b/internal/db/repo_branch.go
index 3eb15fef..94313101 100644
--- a/internal/db/repo_branch.go
+++ b/internal/db/repo_branch.go
@@ -46,7 +46,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
func (repo *Repository) GetBranch(br string) (*Branch, error) {
if !git.IsBranchExist(repo.RepoPath(), br) {
- return nil, errors.ErrBranchNotExist{br}
+ return nil, errors.ErrBranchNotExist{Name: br}
}
return &Branch{
RepoPath: repo.RepoPath(),
@@ -102,7 +102,7 @@ func GetProtectBranchOfRepoByName(repoID int64, name string) (*ProtectBranch, er
if err != nil {
return nil, err
} else if !has {
- return nil, errors.ErrBranchNotExist{name}
+ return nil, errors.ErrBranchNotExist{Name: name}
}
return protectBranch, nil
}
diff --git a/internal/db/repo_editor.go b/internal/db/repo_editor.go
index 38fea3f4..7aa1cd7a 100644
--- a/internal/db/repo_editor.go
+++ b/internal/db/repo_editor.go
@@ -21,10 +21,10 @@ import (
"github.com/gogs/git-module"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/osutil"
"gogs.io/gogs/internal/process"
- "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/tool"
)
@@ -136,7 +136,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
if opts.OldBranch != opts.NewBranch {
// Directly return error if new branch already exists in the server
if git.IsBranchExist(repoPath, opts.NewBranch) {
- return errors.BranchAlreadyExists{opts.NewBranch}
+ return errors.BranchAlreadyExists{Name: opts.NewBranch}
}
// Otherwise, delete branch from local copy in case out of sync
diff --git a/internal/db/token.go b/internal/db/token.go
index 2e2f3492..e7cb7e99 100644
--- a/internal/db/token.go
+++ b/internal/db/token.go
@@ -58,7 +58,7 @@ func NewAccessToken(t *AccessToken) error {
if err != nil {
return err
} else if has {
- return errors.AccessTokenNameAlreadyExist{t.Name}
+ return errors.AccessTokenNameAlreadyExist{Name: t.Name}
}
_, err = x.Insert(t)
diff --git a/internal/db/two_factor.go b/internal/db/two_factor.go
index 45b29705..a46fb992 100644
--- a/internal/db/two_factor.go
+++ b/internal/db/two_factor.go
@@ -118,7 +118,7 @@ func GetTwoFactorByUserID(userID int64) (*TwoFactor, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TwoFactorNotFound{userID}
+ return nil, errors.TwoFactorNotFound{UserID: userID}
}
return t, nil
@@ -189,7 +189,7 @@ func UseRecoveryCode(userID int64, code string) error {
if err != nil {
return fmt.Errorf("get unused code: %v", err)
} else if !has {
- return errors.TwoFactorRecoveryCodeNotFound{code}
+ return errors.TwoFactorRecoveryCodeNotFound{Code: code}
}
recoveryCode.IsUsed = true
diff --git a/internal/db/user.go b/internal/db/user.go
index 603f1905..5f357e28 100644
--- a/internal/db/user.go
+++ b/internal/db/user.go
@@ -886,7 +886,7 @@ func GetUserByKeyID(keyID int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotKeyOwner{keyID}
+ return nil, errors.UserNotKeyOwner{KeyID: keyID}
}
return user, nil
}
@@ -897,7 +897,7 @@ func getUserByID(e Engine, id int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{id, ""}
+ return nil, errors.UserNotExist{UserID: id}
}
return u, nil
}
@@ -913,7 +913,7 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{userID, ""}
+ return nil, errors.UserNotExist{UserID: userID}
}
return GetUserByID(userID)
}
@@ -921,14 +921,14 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
// GetUserByName returns a user by given name.
func GetUserByName(name string) (*User, error) {
if len(name) == 0 {
- return nil, errors.UserNotExist{0, name}
+ return nil, errors.UserNotExist{Name: name}
}
u := &User{LowerName: strings.ToLower(name)}
has, err := x.Get(u)
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{0, name}
+ return nil, errors.UserNotExist{Name: name}
}
return u, nil
}
@@ -1006,7 +1006,7 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
if len(email) == 0 {
- return nil, errors.UserNotExist{0, "email"}
+ return nil, errors.UserNotExist{Name: "email"}
}
email = strings.ToLower(email)
@@ -1030,7 +1030,7 @@ func GetUserByEmail(email string) (*User, error) {
return GetUserByID(emailAddress.UID)
}
- return nil, errors.UserNotExist{0, email}
+ return nil, errors.UserNotExist{Name: email}
}
type SearchUserOptions struct {
diff --git a/internal/db/user_mail.go b/internal/db/user_mail.go
index 5304f13b..440de084 100644
--- a/internal/db/user_mail.go
+++ b/internal/db/user_mail.go
@@ -165,11 +165,11 @@ func MakeEmailPrimary(email *EmailAddress) error {
if err != nil {
return err
} else if !has {
- return errors.EmailNotFound{email.Email}
+ return errors.EmailNotFound{Email: email.Email}
}
if !email.IsActivated {
- return errors.EmailNotVerified{email.Email}
+ return errors.EmailNotVerified{Email: email.Email}
}
user := &User{ID: email.UID}
@@ -177,7 +177,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
if err != nil {
return err
} else if !has {
- return errors.UserNotExist{email.UID, ""}
+ return errors.UserNotExist{UserID: email.UID}
}
// Make sure the former primary email doesn't disappear.
diff --git a/internal/db/webhook.go b/internal/db/webhook.go
index c056f413..96a01971 100644
--- a/internal/db/webhook.go
+++ b/internal/db/webhook.go
@@ -242,7 +242,7 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.WebhookNotExist{bean.ID}
+ return nil, errors.WebhookNotExist{ID: bean.ID}
}
return bean, nil
}
@@ -509,7 +509,7 @@ func GetHookTaskOfWebhookByUUID(webhookID int64, uuid string) (*HookTask, error)
if err != nil {
return nil, err
} else if !has {
- return nil, errors.HookTaskNotExist{webhookID, uuid}
+ return nil, errors.HookTaskNotExist{HookID: webhookID, UUID: uuid}
}
return hookTask, nil
}
diff --git a/internal/email/message.go b/internal/email/message.go
index 00678715..251a5d4e 100644
--- a/internal/email/message.go
+++ b/internal/email/message.go
@@ -203,18 +203,14 @@ func (s *Sender) Send(from string, to []string, msg io.WriterTo) error {
func processMailQueue() {
sender := &Sender{}
-
- for {
- select {
- case msg := <-mailQueue:
- log.Trace("New e-mail sending request %s: %s", msg.GetHeader("To"), msg.Info)
- if err := gomail.Send(sender, msg.Message); err != nil {
- log.Error("Failed to send emails %s: %s - %v", msg.GetHeader("To"), msg.Info, err)
- } else {
- log.Trace("E-mails sent %s: %s", msg.GetHeader("To"), msg.Info)
- }
- msg.confirmChan <- struct{}{}
+ for msg := range mailQueue {
+ log.Trace("New e-mail sending request %s: %s", msg.GetHeader("To"), msg.Info)
+ if err := gomail.Send(sender, msg.Message); err != nil {
+ log.Error("Failed to send emails %s: %s - %v", msg.GetHeader("To"), msg.Info, err)
+ } else {
+ log.Trace("E-mails sent %s: %s", msg.GetHeader("To"), msg.Info)
}
+ msg.confirmChan <- struct{}{}
}
}
diff --git a/internal/form/repo.go b/internal/form/repo.go
index d61bdbf1..12b3a3ff 100644
--- a/internal/form/repo.go
+++ b/internal/form/repo.go
@@ -340,7 +340,7 @@ func (f *NewWiki) Validate(ctx *macaron.Context, errs binding.Errors) binding.Er
type EditRepoFile struct {
TreePath string `binding:"Required;MaxSize(500)"`
Content string `binding:"Required"`
- CommitSummary string `binding:"MaxSize(100)`
+ CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDotSlash;MaxSize(100)"`
@@ -372,8 +372,8 @@ func (f *EditPreviewDiff) Validate(ctx *macaron.Context, errs binding.Errors) bi
//
type UploadRepoFile struct {
- TreePath string `binding:MaxSize(500)"`
- CommitSummary string `binding:"MaxSize(100)`
+ TreePath string `binding:"MaxSize(500)"`
+ CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
@@ -404,7 +404,7 @@ func (f *RemoveUploadFile) Validate(ctx *macaron.Context, errs binding.Errors) b
// \/ \/ \/ \/
type DeleteRepoFile struct {
- CommitSummary string `binding:"MaxSize(100)`
+ CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
diff --git a/internal/httplib/httplib.go b/internal/httplib/httplib.go
index 55b17d93..729e0e03 100644
--- a/internal/httplib/httplib.go
+++ b/internal/httplib/httplib.go
@@ -250,7 +250,7 @@ func (r *Request) getResponse() (*http.Response, error) {
}
if r.req.Method == "GET" && len(paramBody) > 0 {
- if strings.Index(r.url, "?") != -1 {
+ if strings.Contains(r.url, "?") {
r.url += "&" + paramBody
} else {
r.url = r.url + "?" + paramBody
diff --git a/internal/route/api/v1/repo/repo.go b/internal/route/api/v1/repo/repo.go
index a8838ae7..7ea9a870 100644
--- a/internal/route/api/v1/repo/repo.go
+++ b/internal/route/api/v1/repo/repo.go
@@ -13,12 +13,12 @@ import (
api "github.com/gogs/go-gogs-client"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/form"
"gogs.io/gogs/internal/route/api/v1/convert"
- "gogs.io/gogs/internal/conf"
)
func Search(c *context.APIContext) {
@@ -112,7 +112,7 @@ func listUserRepositories(c *context.APIContext, username string) {
if c.User.ID != user.ID {
repos := make([]*api.Repository, len(ownRepos))
for i := range ownRepos {
- repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
+ repos[i] = ownRepos[i].APIFormat(&api.Permission{Admin: true, Push: true, Pull: true})
}
c.JSONSuccess(&repos)
return
@@ -127,7 +127,7 @@ func listUserRepositories(c *context.APIContext, username string) {
numOwnRepos := len(ownRepos)
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
for i := range ownRepos {
- repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
+ repos[i] = ownRepos[i].APIFormat(&api.Permission{Admin: true, Push: true, Pull: true})
}
i := numOwnRepos
@@ -181,7 +181,7 @@ func CreateUserRepo(c *context.APIContext, owner *db.User, opt api.CreateRepoOpt
return
}
- c.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
+ c.JSON(201, repo.APIFormat(&api.Permission{Admin: true, Push: true, Pull: true}))
}
func Create(c *context.APIContext, opt api.CreateRepoOption) {
@@ -283,7 +283,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) {
}
log.Trace("Repository migrated: %s/%s", ctxUser.Name, f.RepoName)
- c.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
+ c.JSON(201, repo.APIFormat(&api.Permission{Admin: true, Push: true, Pull: true}))
}
// FIXME: inject in the handler chain
diff --git a/internal/route/api/v1/user/app.go b/internal/route/api/v1/user/app.go
index 5db0175b..fdf11c09 100644
--- a/internal/route/api/v1/user/app.go
+++ b/internal/route/api/v1/user/app.go
@@ -23,7 +23,7 @@ func ListAccessTokens(c *context.APIContext) {
apiTokens := make([]*api.AccessToken, len(tokens))
for i := range tokens {
- apiTokens[i] = &api.AccessToken{tokens[i].Name, tokens[i].Sha1}
+ apiTokens[i] = &api.AccessToken{Name: tokens[i].Name, Sha1: tokens[i].Sha1}
}
c.JSONSuccess(&apiTokens)
}
@@ -41,5 +41,5 @@ func CreateAccessToken(c *context.APIContext, form api.CreateAccessTokenOption)
}
return
}
- c.JSON(http.StatusCreated, &api.AccessToken{t.Name, t.Sha1})
+ c.JSON(http.StatusCreated, &api.AccessToken{Name: t.Name, Sha1: t.Sha1})
}
diff --git a/internal/route/repo/issue.go b/internal/route/repo/issue.go
index c8756d28..5495402a 100644
--- a/internal/route/repo/issue.go
+++ b/internal/route/repo/issue.go
@@ -1071,10 +1071,9 @@ func DeleteLabel(c *context.Context) {
c.Flash.Success(c.Tr("repo.issues.label_deletion_success"))
}
- c.JSON(200, map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": c.Repo.MakeURL("labels"),
})
- return
}
func Milestones(c *context.Context) {
diff --git a/internal/route/user/auth.go b/internal/route/user/auth.go
index 7d72eb16..88b0d1e8 100644
--- a/internal/route/user/auth.go
+++ b/internal/route/user/auth.go
@@ -438,10 +438,10 @@ func Activate(c *context.Context) {
func ActivateEmail(c *context.Context) {
code := c.Query("code")
- email_string := c.Query("email")
+ emailAddr := c.Query("email")
// Verify code.
- if email := db.VerifyActiveEmailCode(code, email_string); email != nil {
+ if email := db.VerifyActiveEmailCode(code, emailAddr); email != nil {
if err := email.Activate(); err != nil {
c.ServerError("ActivateEmail", err)
}
@@ -451,7 +451,6 @@ func ActivateEmail(c *context.Context) {
}
c.SubURLRedirect("/user/settings/email")
- return
}
func ForgotPasswd(c *context.Context) {
diff --git a/internal/template/template.go b/internal/template/template.go
index 1023d7b3..5d254e50 100644
--- a/internal/template/template.go
+++ b/internal/template/template.go
@@ -184,38 +184,6 @@ func ToUTF8WithErr(content []byte) (error, string) {
return err, result
}
-// FIXME: Unused function
-func ToUTF8(content string) string {
- _, res := ToUTF8WithErr([]byte(content))
- return res
-}
-
-// Replaces all prefixes 'old' in 's' with 'new'.
-// FIXME: Unused function
-func ReplaceLeft(s, old, new string) string {
- old_len, new_len, i, n := len(old), len(new), 0, 0
- for ; i < len(s) && strings.HasPrefix(s[i:], old); n += 1 {
- i += old_len
- }
-
- // simple optimization
- if n == 0 {
- return s
- }
-
- // allocating space for the new string
- newLen := n*new_len + len(s[i:])
- replacement := make([]byte, newLen, newLen)
-
- j := 0
- for ; j < n*new_len; j += new_len {
- copy(replacement[j:j+new_len], new)
- }
-
- copy(replacement[j:], s[i:])
- return string(replacement)
-}
-
// RenderCommitMessage renders commit message with special links.
func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) string {
cleanMsg := template.HTMLEscapeString(msg)
diff --git a/internal/tool/file.go b/internal/tool/file.go
index 6ca4136a..169bc511 100644
--- a/internal/tool/file.go
+++ b/internal/tool/file.go
@@ -31,26 +31,6 @@ func IsVideoFile(data []byte) bool {
return strings.Contains(http.DetectContentType(data), "video/")
}
-const (
- Byte = 1
- KByte = Byte * 1024
- MByte = KByte * 1024
- GByte = MByte * 1024
- TByte = GByte * 1024
- PByte = TByte * 1024
- EByte = PByte * 1024
-)
-
-var bytesSizeTable = map[string]uint64{
- "b": Byte,
- "kb": KByte,
- "mb": MByte,
- "gb": GByte,
- "tb": TByte,
- "pb": PByte,
- "eb": EByte,
-}
-
func logn(n, b float64) float64 {
return math.Log(n) / math.Log(b)
}
diff --git a/internal/tool/tool.go b/internal/tool/tool.go
index 7e6fc813..2410b4d6 100644
--- a/internal/tool/tool.go
+++ b/internal/tool/tool.go
@@ -367,37 +367,37 @@ func TimeSince(t time.Time, lang string) template.HTML {
func Subtract(left interface{}, right interface{}) interface{} {
var rleft, rright int64
var fleft, fright float64
- var isInt bool = true
- switch left.(type) {
+ var isInt = true
+ switch left := left.(type) {
case int:
- rleft = int64(left.(int))
+ rleft = int64(left)
case int8:
- rleft = int64(left.(int8))
+ rleft = int64(left)
case int16:
- rleft = int64(left.(int16))
+ rleft = int64(left)
case int32:
- rleft = int64(left.(int32))
+ rleft = int64(left)
case int64:
- rleft = left.(int64)
+ rleft = left
case float32:
- fleft = float64(left.(float32))
+ fleft = float64(left)
isInt = false
case float64:
- fleft = left.(float64)
+ fleft = left
isInt = false
}
- switch right.(type) {
+ switch right := right.(type) {
case int:
- rright = int64(right.(int))
+ rright = int64(right)
case int8:
- rright = int64(right.(int8))
+ rright = int64(right)
case int16:
- rright = int64(right.(int16))
+ rright = int64(right)
case int32:
- rright = int64(right.(int32))
+ rright = int64(right)
case int64:
- rright = right.(int64)
+ rright = right
case float32:
fright = float64(left.(float32))
isInt = false