fix more lint errors

dependabot/go_modules/modernc.org/sqlite-1.37.0
Joe Chen 2025-04-01 22:40:07 -04:00
parent 6e823fa2b2
commit 747a7b0ce8
11 changed files with 35 additions and 58 deletions

View File

@ -78,12 +78,12 @@ func runImportLocale(c *cli.Context) error {
// this breaks INI parser, we need to fix that. // this breaks INI parser, we need to fix that.
sr, err := os.Open(source) sr, err := os.Open(source)
if err != nil { if err != nil {
return fmt.Errorf("Open: %v", err) return fmt.Errorf("open: %v", err)
} }
tw, err := os.Create(target) tw, err := os.Create(target)
if err != nil { if err != nil {
return fmt.Errorf("Create: %v", err) return fmt.Errorf("create: %v", err)
} }
scanner := bufio.NewScanner(sr) scanner := bufio.NewScanner(sr)

View File

@ -72,9 +72,9 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment,
defer fw.Close() defer fw.Close()
if _, err = fw.Write(buf); err != nil { 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 { } 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 { if _, err := x.Insert(attach); err != nil {

View File

@ -354,7 +354,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
} }
if err = sess.Commit(); err != nil { if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("commit: %v", err)
} }
if issue.IsPull { if issue.IsPull {
@ -485,7 +485,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
} }
if err = sess.Commit(); err != nil { if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("commit: %v", err)
} }
if issue.IsPull { if issue.IsPull {
@ -770,11 +770,11 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
LableIDs: labelIDs, LableIDs: labelIDs,
Attachments: uuids, Attachments: uuids,
}); err != nil { }); err != nil {
return fmt.Errorf("newIssue: %v", err) return fmt.Errorf("new issue: %v", err)
} }
if err = sess.Commit(); err != nil { if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("commit: %v", err)
} }
if err = NotifyWatchers(&Action{ if err = NotifyWatchers(&Action{

View File

@ -21,15 +21,15 @@ import (
) )
const ( const (
MAIL_AUTH_ACTIVATE = "auth/activate" tmplAuthActivate = "auth/activate"
MAIL_AUTH_ACTIVATE_EMAIL = "auth/activate_email" tmplAuthActivateEmail = "auth/activate_email"
MAIL_AUTH_RESET_PASSWORD = "auth/reset_passwd" tmplAuthResetPassword = "auth/reset_passwd"
MAIL_AUTH_REGISTER_NOTIFY = "auth/register_notify" tmplAuthRegisterNotify = "auth/register_notify"
MAIL_ISSUE_COMMENT = "issue/comment" tmplIssueComment = "issue/comment"
MAIL_ISSUE_MENTION = "issue/mention" tmplIssueMention = "issue/mention"
MAIL_NOTIFY_COLLABORATOR = "notify/collaborator" tmplNotifyCollaborator = "notify/collaborator"
) )
var ( var (
@ -122,11 +122,11 @@ func SendUserMail(_ *macaron.Context, u User, tpl, code, subject, info string) {
} }
func SendActivateAccountMail(c *macaron.Context, u User) { 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) { 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. // SendActivateAccountMail sends confirmation email.
@ -137,7 +137,7 @@ func SendActivateEmailMail(c *macaron.Context, u User, email string) {
"Code": u.GenerateEmailActivateCode(email), "Code": u.GenerateEmailActivateCode(email),
"Email": email, "Email": email,
} }
body, err := render(MAIL_AUTH_ACTIVATE_EMAIL, data) body, err := render(tmplAuthActivateEmail, data)
if err != nil { if err != nil {
log.Error("HTMLString: %v", err) log.Error("HTMLString: %v", err)
return return
@ -154,7 +154,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u User) {
data := map[string]any{ data := map[string]any{
"Username": u.DisplayName(), "Username": u.DisplayName(),
} }
body, err := render(MAIL_AUTH_REGISTER_NOTIFY, data) body, err := render(tmplAuthRegisterNotify, data)
if err != nil { if err != nil {
log.Error("HTMLString: %v", err) log.Error("HTMLString: %v", err)
return return
@ -175,7 +175,7 @@ func SendCollaboratorMail(u, doer User, repo Repository) {
"RepoName": repo.FullName(), "RepoName": repo.FullName(),
"Link": repo.HTMLURL(), "Link": repo.HTMLURL(),
} }
body, err := render(MAIL_NOTIFY_COLLABORATOR, data) body, err := render(tmplNotifyCollaborator, data)
if err != nil { if err != nil {
log.Error("HTMLString: %v", err) log.Error("HTMLString: %v", err)
return return
@ -216,7 +216,7 @@ func SendIssueCommentMail(issue Issue, repo Repository, doer User, tos []string)
return 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. // 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 { if len(tos) == 0 {
return return
} }
Send(composeIssueMessage(issue, repo, doer, MAIL_ISSUE_MENTION, tos, "issue mention")) Send(composeIssueMessage(issue, repo, doer, tmplIssueMention, tos, "issue mention"))
} }

View File

@ -9,7 +9,6 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/tls" "crypto/tls"
"encoding/xml"
"io" "io"
"log" "log"
"mime/multipart" "mime/multipart"
@ -22,8 +21,6 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
jsoniter "github.com/json-iterator/go"
) )
var ( var (
@ -412,26 +409,6 @@ func (r *Request) ToFile(filename string) error {
return err 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. // Response executes request client gets response manually.
func (r *Request) Response() (*http.Response, error) { func (r *Request) Response() (*http.Response, error) {
return r.getResponse() return r.getResponse()

View File

@ -17,7 +17,7 @@ import (
var ErrExecTimeout = errors.New("process execution timeout") 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. // Process represents a running process calls shell command.
type Process struct { 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. // 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) { func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
if timeout == -1 { if timeout == -1 {
timeout = DEFAULT_TIMEOUT timeout = defaultTimeout
} }
bufOut := new(bytes.Buffer) bufOut := new(bytes.Buffer)

View File

@ -11,7 +11,7 @@ import (
"gogs.io/gogs/internal/database" "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)) apiUsers := make([]*api.User, len(users))
for i := range users { for i := range users {
apiUsers[i] = users[i].APIFormat() apiUsers[i] = users[i].APIFormat()
@ -25,7 +25,7 @@ func listUserFollowers(c *context.APIContext, u *database.User) {
c.Error(err, "list followers") c.Error(err, "list followers")
return return
} }
responseApiUsers(c, users) responseAPIUsers(c, users)
} }
func ListMyFollowers(c *context.APIContext) { func ListMyFollowers(c *context.APIContext) {
@ -46,7 +46,7 @@ func listUserFollowing(c *context.APIContext, u *database.User) {
c.Error(err, "list followings") c.Error(err, "list followings")
return return
} }
responseApiUsers(c, users) responseAPIUsers(c, users)
} }
func ListMyFollowing(c *context.APIContext) { func ListMyFollowing(c *context.APIContext) {

View File

@ -402,12 +402,12 @@ func SignUpPost(c *context.Context, cpt *captcha.Captcha, f form.Register) {
// parseUserFromCode returns user by username encoded in code. // parseUserFromCode returns user by username encoded in code.
// It returns nil if code or username is invalid. // It returns nil if code or username is invalid.
func parseUserFromCode(code string) (user *database.User) { func parseUserFromCode(code string) (user *database.User) {
if len(code) <= tool.TIME_LIMIT_CODE_LENGTH { if len(code) <= tool.TimeLimitCodeLength {
return nil return nil
} }
// Use tail hex username to query user // 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 b, err := hex.DecodeString(hexStr); err == nil {
if user, err = database.Handle.Users().GetByUsername(gocontext.TODO(), string(b)); user != nil { if user, err = database.Handle.Users().GetByUsername(gocontext.TODO(), string(b)); user != nil {
return user return user
@ -425,7 +425,7 @@ func verifyUserActiveCode(code string) (user *database.User) {
if user = parseUserFromCode(code); user != nil { if user = parseUserFromCode(code); user != nil {
// time limit code // 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 data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Password + user.Rands
if tool.VerifyTimeLimitCode(data, minutes, prefix) { if tool.VerifyTimeLimitCode(data, minutes, prefix) {
@ -441,7 +441,7 @@ func verifyActiveEmailCode(code, email string) *database.EmailAddress {
if user := parseUserFromCode(code); user != nil { if user := parseUserFromCode(code); user != nil {
// time limit code // 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 data := com.ToStr(user.ID) + email + user.LowerName + user.Password + user.Rands
if tool.VerifyTimeLimitCode(data, minutes, prefix) { if tool.VerifyTimeLimitCode(data, minutes, prefix) {

View File

@ -164,11 +164,11 @@ func ToUTF8WithErr(content []byte) (error, string) {
encoding, _ := charset.Lookup(charsetLabel) encoding, _ := charset.Lookup(charsetLabel)
if encoding == nil { 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 // 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)) result, n, err := transform.String(encoding.NewDecoder(), string(content))
if err != nil { if err != nil {
result = result + string(content[n:]) result = result + string(content[n:])

View File

@ -89,7 +89,7 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
return false 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. // CreateTimeLimitCode generates a time limit code based on given input data.
// Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string // Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string

View File

@ -40,7 +40,7 @@ func TestGenerateActivateCode(t *testing.T) {
) )
code := GenerateActivateCode(1, "alice@example.com", "Alice", "123456", "rands") 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) assert.True(t, got)
} }