From e452d94fc842da6623c8fde67b9d71a1ee739f0a Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 6 Mar 2022 17:55:17 +0800 Subject: [PATCH] autofix: format code with gofumpt and gofmt (#6803) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- internal/auth/pam/pam.go | 1 + internal/cmd/backup.go | 6 ++++-- internal/cmd/cert.go | 1 + internal/cmd/web.go | 4 ++-- internal/conf/static_minwinsvc.go | 1 + internal/db/models.go | 2 +- internal/db/perms_test.go | 1 + internal/db/webhook_dingtalk.go | 10 +++++----- internal/gitutil/error.go | 1 - internal/process/manager.go | 10 +++++----- internal/route/lfs/route.go | 1 - internal/route/repo/pull.go | 1 - 12 files changed, 21 insertions(+), 18 deletions(-) diff --git a/internal/auth/pam/pam.go b/internal/auth/pam/pam.go index 521cd4f08..0777bf7c2 100644 --- a/internal/auth/pam/pam.go +++ b/internal/auth/pam/pam.go @@ -1,3 +1,4 @@ +//go:build pam // +build pam // Copyright 2014 The Gogs Authors. All rights reserved. diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 874b1be00..c5e17e16f 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -42,8 +42,10 @@ portable among all supported database engines.`, }, } -const currentBackupFormatVersion = 1 -const archiveRootDir = "gogs-backup" +const ( + currentBackupFormatVersion = 1 + archiveRootDir = "gogs-backup" +) func runBackup(c *cli.Context) error { zip.Verbose = c.Bool("verbose") diff --git a/internal/cmd/cert.go b/internal/cmd/cert.go index 7c91c2c67..c8280a120 100644 --- a/internal/cmd/cert.go +++ b/internal/cmd/cert.go @@ -1,3 +1,4 @@ +//go:build cert // +build cert // Copyright 2009 The Go Authors. All rights reserved. diff --git a/internal/cmd/web.go b/internal/cmd/web.go index c4ceda174..358ff832a 100644 --- a/internal/cmd/web.go +++ b/internal/cmd/web.go @@ -456,7 +456,6 @@ func runWeb(c *cli.Context) error { Post(bindIgnErr(form.AddSSHKey{}), repo.SettingsDeployKeysPost) m.Post("/delete", repo.DeleteDeployKey) }) - }, func(c *context.Context) { c.Data["PageIsSettings"] = true }) @@ -734,7 +733,8 @@ func runWeb(c *cli.Context) error { tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, }, - }, Handler: m} + }, Handler: m, + } err = server.ListenAndServeTLS(conf.Server.CertFile, conf.Server.KeyFile) case "fcgi": diff --git a/internal/conf/static_minwinsvc.go b/internal/conf/static_minwinsvc.go index aebfaf6da..0b167714e 100644 --- a/internal/conf/static_minwinsvc.go +++ b/internal/conf/static_minwinsvc.go @@ -1,3 +1,4 @@ +//go:build minwinsvc // +build minwinsvc // Copyright 2015 The Gogs Authors. All rights reserved. diff --git a/internal/db/models.go b/internal/db/models.go index 82968ae31..1be08c918 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -83,7 +83,7 @@ func getEngine() (*xorm.Engine, error) { connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8mb4&parseTime=true", conf.Database.User, conf.Database.Password, conf.Database.Host, conf.Database.Name, Param) } - var engineParams = map[string]string{"rowFormat": "DYNAMIC"} + engineParams := map[string]string{"rowFormat": "DYNAMIC"} return xorm.NewEngineWithParams(conf.Database.Type, connStr, engineParams) case "postgres": diff --git a/internal/db/perms_test.go b/internal/db/perms_test.go index c3b463ee6..e242f8438 100644 --- a/internal/db/perms_test.go +++ b/internal/db/perms_test.go @@ -41,6 +41,7 @@ func Test_perms(t *testing.T) { }) } } + func test_perms_AccessMode(t *testing.T, db *perms) { // Set up permissions err := db.SetRepoPerms(1, map[int64]AccessMode{ diff --git a/internal/db/webhook_dingtalk.go b/internal/db/webhook_dingtalk.go index 13287f5ef..88246ca9d 100644 --- a/internal/db/webhook_dingtalk.go +++ b/internal/db/webhook_dingtalk.go @@ -18,7 +18,7 @@ const ( DingtalkNotificationTitle = "Gogs Notification" ) -//Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 +// Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 type DingtalkActionCard struct { Title string `json:"title"` Text string `json:"text"` @@ -28,13 +28,13 @@ type DingtalkActionCard struct { SingleURL string `json:"singleURL"` } -//Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 +// Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 type DingtalkAtObject struct { AtMobiles []string `json:"atMobiles"` IsAtAll bool `json:"isAtAll"` } -//Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 +// Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 type DingtalkPayload struct { MsgType string `json:"msgtype"` At DingtalkAtObject `json:"at"` @@ -57,7 +57,7 @@ func NewDingtalkActionCard(singleTitle, singleURL string) DingtalkActionCard { } } -//TODO: add content +// TODO: add content func GetDingtalkPayload(p api.Payloader, event HookEventType) (payload *DingtalkPayload, err error) { switch event { case HOOK_EVENT_CREATE: @@ -255,7 +255,7 @@ func getDingtalkReleasePayload(p *api.ReleasePayload) (*DingtalkPayload, error) return &DingtalkPayload{MsgType: "actionCard", ActionCard: actionCard}, nil } -//Format link addr and title into markdown style +// Format link addr and title into markdown style func MarkdownLinkFormatter(link, text string) string { return "[" + text + "](" + link + ")" } diff --git a/internal/gitutil/error.go b/internal/gitutil/error.go index 20aa3b51d..205546aa9 100644 --- a/internal/gitutil/error.go +++ b/internal/gitutil/error.go @@ -20,7 +20,6 @@ type Error struct { func (e Error) NotFound() bool { return IsErrSubmoduleNotExist(e.error) || IsErrRevisionNotExist(e.error) - } // NewError wraps given error. diff --git a/internal/process/manager.go b/internal/process/manager.go index 274e63df2..042486a53 100644 --- a/internal/process/manager.go +++ b/internal/process/manager.go @@ -15,9 +15,7 @@ import ( log "unknwon.dev/clog/v2" ) -var ( - ErrExecTimeout = errors.New("process execution timeout") -) +var ErrExecTimeout = errors.New("process execution timeout") const DEFAULT_TIMEOUT = 60 * time.Second @@ -41,8 +39,10 @@ func (c *pidCounter) PID() int64 { return c.pid } -var counter = new(pidCounter) -var Processes []*Process +var ( + counter = new(pidCounter) + Processes []*Process +) // Add adds a process to global list and returns its PID. func Add(desc string, cmd *exec.Cmd) int64 { diff --git a/internal/route/lfs/route.go b/internal/route/lfs/route.go index ff1bd591c..0fd9617bf 100644 --- a/internal/route/lfs/route.go +++ b/internal/route/lfs/route.go @@ -27,7 +27,6 @@ func RegisterRoutes(r *macaron.Router) { r.Group("", func() { r.Post("/objects/batch", authorize(db.AccessModeRead), verifyAccept, verifyContentTypeJSON, serveBatch) r.Group("/objects/basic", func() { - basic := &basicHandler{ defaultStorage: lfsutil.Storage(conf.LFS.Storage), storagers: map[lfsutil.Storage]lfsutil.Storager{ diff --git a/internal/route/repo/pull.go b/internal/route/repo/pull.go index 88c452abf..68389532f 100644 --- a/internal/route/repo/pull.go +++ b/internal/route/repo/pull.go @@ -553,7 +553,6 @@ func PrepareCompareDiff( meta *gitutil.PullRequestMeta, headBranch string, ) bool { - var ( repo = c.Repo.Repository err error