diff --git a/internal/cmd/import.go b/internal/cmd/import.go index 79f0b51ba..03ef6b869 100644 --- a/internal/cmd/import.go +++ b/internal/cmd/import.go @@ -78,12 +78,12 @@ func runImportLocale(c *cli.Context) error { // this breaks INI parser, we need to fix that. sr, err := os.Open(source) if err != nil { - return fmt.Errorf("Open: %v", err) + return fmt.Errorf("open: %v", err) } tw, err := os.Create(target) if err != nil { - return fmt.Errorf("Create: %v", err) + return fmt.Errorf("create: %v", err) } scanner := bufio.NewScanner(sr) diff --git a/internal/database/attachment.go b/internal/database/attachment.go index b278e8b86..532a1ffeb 100644 --- a/internal/database/attachment.go +++ b/internal/database/attachment.go @@ -72,9 +72,9 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, defer fw.Close() if _, err = fw.Write(buf); err != nil { - return nil, fmt.Errorf("Write: %v", err) + return nil, fmt.Errorf("write: %v", err) } else if _, err = io.Copy(fw, file); err != nil { - return nil, fmt.Errorf("Copy: %v", err) + return nil, fmt.Errorf("copy: %v", err) } if _, err := x.Insert(attach); err != nil { diff --git a/internal/database/issue.go b/internal/database/issue.go index 812e29510..a12a958fa 100644 --- a/internal/database/issue.go +++ b/internal/database/issue.go @@ -354,7 +354,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { } if err = sess.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("commit: %v", err) } if issue.IsPull { @@ -485,7 +485,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e } if err = sess.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("commit: %v", err) } if issue.IsPull { @@ -770,11 +770,11 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) LableIDs: labelIDs, Attachments: uuids, }); err != nil { - return fmt.Errorf("newIssue: %v", err) + return fmt.Errorf("new issue: %v", err) } if err = sess.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("commit: %v", err) } if err = NotifyWatchers(&Action{ diff --git a/internal/email/email.go b/internal/email/email.go index aad5ab598..55c092d19 100644 --- a/internal/email/email.go +++ b/internal/email/email.go @@ -21,15 +21,15 @@ import ( ) const ( - MAIL_AUTH_ACTIVATE = "auth/activate" - MAIL_AUTH_ACTIVATE_EMAIL = "auth/activate_email" - MAIL_AUTH_RESET_PASSWORD = "auth/reset_passwd" - MAIL_AUTH_REGISTER_NOTIFY = "auth/register_notify" + tmplAuthActivate = "auth/activate" + tmplAuthActivateEmail = "auth/activate_email" + tmplAuthResetPassword = "auth/reset_passwd" + tmplAuthRegisterNotify = "auth/register_notify" - MAIL_ISSUE_COMMENT = "issue/comment" - MAIL_ISSUE_MENTION = "issue/mention" + tmplIssueComment = "issue/comment" + tmplIssueMention = "issue/mention" - MAIL_NOTIFY_COLLABORATOR = "notify/collaborator" + tmplNotifyCollaborator = "notify/collaborator" ) var ( @@ -122,11 +122,11 @@ func SendUserMail(_ *macaron.Context, u User, tpl, code, subject, info string) { } func SendActivateAccountMail(c *macaron.Context, u User) { - SendUserMail(c, u, MAIL_AUTH_ACTIVATE, u.GenerateEmailActivateCode(u.Email()), c.Tr("mail.activate_account"), "activate account") + SendUserMail(c, u, tmplAuthActivate, u.GenerateEmailActivateCode(u.Email()), c.Tr("mail.activate_account"), "activate account") } func SendResetPasswordMail(c *macaron.Context, u User) { - SendUserMail(c, u, MAIL_AUTH_RESET_PASSWORD, u.GenerateEmailActivateCode(u.Email()), c.Tr("mail.reset_password"), "reset password") + SendUserMail(c, u, tmplAuthResetPassword, u.GenerateEmailActivateCode(u.Email()), c.Tr("mail.reset_password"), "reset password") } // SendActivateAccountMail sends confirmation email. @@ -137,7 +137,7 @@ func SendActivateEmailMail(c *macaron.Context, u User, email string) { "Code": u.GenerateEmailActivateCode(email), "Email": email, } - body, err := render(MAIL_AUTH_ACTIVATE_EMAIL, data) + body, err := render(tmplAuthActivateEmail, data) if err != nil { log.Error("HTMLString: %v", err) return @@ -154,7 +154,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u User) { data := map[string]any{ "Username": u.DisplayName(), } - body, err := render(MAIL_AUTH_REGISTER_NOTIFY, data) + body, err := render(tmplAuthRegisterNotify, data) if err != nil { log.Error("HTMLString: %v", err) return @@ -175,7 +175,7 @@ func SendCollaboratorMail(u, doer User, repo Repository) { "RepoName": repo.FullName(), "Link": repo.HTMLURL(), } - body, err := render(MAIL_NOTIFY_COLLABORATOR, data) + body, err := render(tmplNotifyCollaborator, data) if err != nil { log.Error("HTMLString: %v", err) return @@ -216,7 +216,7 @@ func SendIssueCommentMail(issue Issue, repo Repository, doer User, tos []string) return } - Send(composeIssueMessage(issue, repo, doer, MAIL_ISSUE_COMMENT, tos, "issue comment")) + Send(composeIssueMessage(issue, repo, doer, tmplIssueComment, tos, "issue comment")) } // SendIssueMentionMail composes and sends issue mention emails to target receivers. @@ -224,5 +224,5 @@ func SendIssueMentionMail(issue Issue, repo Repository, doer User, tos []string) if len(tos) == 0 { return } - Send(composeIssueMessage(issue, repo, doer, MAIL_ISSUE_MENTION, tos, "issue mention")) + Send(composeIssueMessage(issue, repo, doer, tmplIssueMention, tos, "issue mention")) } diff --git a/internal/httplib/httplib.go b/internal/httplib/httplib.go index 942b83015..1753d3ece 100644 --- a/internal/httplib/httplib.go +++ b/internal/httplib/httplib.go @@ -9,7 +9,6 @@ import ( "bytes" "context" "crypto/tls" - "encoding/xml" "io" "log" "mime/multipart" @@ -22,8 +21,6 @@ import ( "strings" "sync" "time" - - jsoniter "github.com/json-iterator/go" ) var ( @@ -412,26 +409,6 @@ func (r *Request) ToFile(filename string) error { return err } -// ToJson returns the map that marshals from the body bytes as json in response . -// it calls Response inner. -func (r *Request) ToJson(v any) error { - data, err := r.Bytes() - if err != nil { - return err - } - return jsoniter.Unmarshal(data, v) -} - -// ToXml returns the map that marshals from the body bytes as xml in response . -// it calls Response inner. -func (r *Request) ToXml(v any) error { - data, err := r.Bytes() - if err != nil { - return err - } - return xml.Unmarshal(data, v) -} - // Response executes request client gets response manually. func (r *Request) Response() (*http.Response, error) { return r.getResponse() diff --git a/internal/process/manager.go b/internal/process/manager.go index 042486a53..61bd49fbe 100644 --- a/internal/process/manager.go +++ b/internal/process/manager.go @@ -17,7 +17,7 @@ import ( var ErrExecTimeout = errors.New("process execution timeout") -const DEFAULT_TIMEOUT = 60 * time.Second +const defaultTimeout = 60 * time.Second // Process represents a running process calls shell command. type Process struct { @@ -77,7 +77,7 @@ func Remove(pid int64) bool { // Exec starts executing a shell command in given path, it tracks corresponding process and timeout. func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) { if timeout == -1 { - timeout = DEFAULT_TIMEOUT + timeout = defaultTimeout } bufOut := new(bytes.Buffer) diff --git a/internal/route/api/v1/user/follower.go b/internal/route/api/v1/user/follower.go index 1b8910773..90fa868b8 100644 --- a/internal/route/api/v1/user/follower.go +++ b/internal/route/api/v1/user/follower.go @@ -11,7 +11,7 @@ import ( "gogs.io/gogs/internal/database" ) -func responseApiUsers(c *context.APIContext, users []*database.User) { +func responseAPIUsers(c *context.APIContext, users []*database.User) { apiUsers := make([]*api.User, len(users)) for i := range users { apiUsers[i] = users[i].APIFormat() @@ -25,7 +25,7 @@ func listUserFollowers(c *context.APIContext, u *database.User) { c.Error(err, "list followers") return } - responseApiUsers(c, users) + responseAPIUsers(c, users) } func ListMyFollowers(c *context.APIContext) { @@ -46,7 +46,7 @@ func listUserFollowing(c *context.APIContext, u *database.User) { c.Error(err, "list followings") return } - responseApiUsers(c, users) + responseAPIUsers(c, users) } func ListMyFollowing(c *context.APIContext) { diff --git a/internal/route/user/auth.go b/internal/route/user/auth.go index 52d8fc25b..a9b2a0792 100644 --- a/internal/route/user/auth.go +++ b/internal/route/user/auth.go @@ -402,12 +402,12 @@ func SignUpPost(c *context.Context, cpt *captcha.Captcha, f form.Register) { // parseUserFromCode returns user by username encoded in code. // It returns nil if code or username is invalid. func parseUserFromCode(code string) (user *database.User) { - if len(code) <= tool.TIME_LIMIT_CODE_LENGTH { + if len(code) <= tool.TimeLimitCodeLength { return nil } // Use tail hex username to query user - hexStr := code[tool.TIME_LIMIT_CODE_LENGTH:] + hexStr := code[tool.TimeLimitCodeLength:] if b, err := hex.DecodeString(hexStr); err == nil { if user, err = database.Handle.Users().GetByUsername(gocontext.TODO(), string(b)); user != nil { return user @@ -425,7 +425,7 @@ func verifyUserActiveCode(code string) (user *database.User) { if user = parseUserFromCode(code); user != nil { // time limit code - prefix := code[:tool.TIME_LIMIT_CODE_LENGTH] + prefix := code[:tool.TimeLimitCodeLength] data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Password + user.Rands if tool.VerifyTimeLimitCode(data, minutes, prefix) { @@ -441,7 +441,7 @@ func verifyActiveEmailCode(code, email string) *database.EmailAddress { if user := parseUserFromCode(code); user != nil { // time limit code - prefix := code[:tool.TIME_LIMIT_CODE_LENGTH] + prefix := code[:tool.TimeLimitCodeLength] data := com.ToStr(user.ID) + email + user.LowerName + user.Password + user.Rands if tool.VerifyTimeLimitCode(data, minutes, prefix) { diff --git a/internal/template/template.go b/internal/template/template.go index d8bd48dcc..348bef049 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -164,11 +164,11 @@ func ToUTF8WithErr(content []byte) (error, string) { encoding, _ := charset.Lookup(charsetLabel) if encoding == nil { - return fmt.Errorf("Unknown encoding: %s", charsetLabel), string(content) + return fmt.Errorf("unknown encoding: %s", charsetLabel), string(content) } // If there is an error, we concatenate the nicely decoded part and the - // original left over. This way we won't loose data. + // original left over. This way we won't lose data. result, n, err := transform.String(encoding.NewDecoder(), string(content)) if err != nil { result = result + string(content[n:]) diff --git a/internal/tool/tool.go b/internal/tool/tool.go index ab46a8840..d0c8874f0 100644 --- a/internal/tool/tool.go +++ b/internal/tool/tool.go @@ -89,7 +89,7 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool { return false } -const TIME_LIMIT_CODE_LENGTH = 12 + 6 + 40 +const TimeLimitCodeLength = 12 + 6 + 40 // CreateTimeLimitCode generates a time limit code based on given input data. // Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string diff --git a/internal/userutil/userutil_test.go b/internal/userutil/userutil_test.go index 6cdd6dd34..25d0341a4 100644 --- a/internal/userutil/userutil_test.go +++ b/internal/userutil/userutil_test.go @@ -40,7 +40,7 @@ func TestGenerateActivateCode(t *testing.T) { ) code := GenerateActivateCode(1, "alice@example.com", "Alice", "123456", "rands") - got := tool.VerifyTimeLimitCode("1alice@example.comalice123456rands", conf.Auth.ActivateCodeLives, code[:tool.TIME_LIMIT_CODE_LENGTH]) + got := tool.VerifyTimeLimitCode("1alice@example.comalice123456rands", conf.Auth.ActivateCodeLives, code[:tool.TimeLimitCodeLength]) assert.True(t, got) }