From 06e7b0ab7020c4e1a648e52670162a865b71f50b Mon Sep 17 00:00:00 2001 From: guangwu Date: Fri, 7 Jul 2023 11:00:36 +0800 Subject: [PATCH] chore: use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) Signed-off-by: guoguangwu --- commands/command.go | 1 - models/Member.go | 2 +- utils/dingtalk/dingtalk.go | 8 ++++---- utils/requests/requests.go | 3 +-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/commands/command.go b/commands/command.go index 74555463..dbdea324 100644 --- a/commands/command.go +++ b/commands/command.go @@ -20,7 +20,6 @@ import ( beegoCache "github.com/beego/beego/v2/client/cache" _ "github.com/beego/beego/v2/client/cache/memcache" "github.com/beego/beego/v2/client/cache/redis" - _ "github.com/beego/beego/v2/client/cache/redis" "github.com/beego/beego/v2/client/orm" "github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/server/web" diff --git a/models/Member.go b/models/Member.go index 481965d5..d217cd72 100644 --- a/models/Member.go +++ b/models/Member.go @@ -201,7 +201,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) { if len(m.Email) > 0 { // 如果member配置的email和ldap配置的email不同 if m.Email != ldap_mail { - return m, errors.New(fmt.Sprintf("ldap配置的email(%s)与数据库中已有email({%s})不同, 请联系管理员修改", ldap_mail, m.Email)) + return m, fmt.Errorf("ldap配置的email(%s)与数据库中已有email({%s})不同, 请联系管理员修改", ldap_mail, m.Email) } } else { // 如果member未配置email,则用ldap的email配置 diff --git a/utils/dingtalk/dingtalk.go b/utils/dingtalk/dingtalk.go index fa8e6883..90c01ad6 100644 --- a/utils/dingtalk/dingtalk.go +++ b/utils/dingtalk/dingtalk.go @@ -62,7 +62,7 @@ func (d *DingTalkAgent) GetUserIDByCode(code string) (string, error) { errcode := rdata["errcode"].(float64) if errcode != 0 { - return "", errors.New(fmt.Sprintf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string))) + return "", fmt.Errorf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string)) } userid := rdata["userid"].(string) @@ -100,7 +100,7 @@ func (d *DingTalkAgent) GetUserNameAndAvatarByUserID(userid string) (string, str errcode := rdata["errcode"].(float64) if errcode != 0 { - return "", "", errors.New(fmt.Sprintf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string))) + return "", "", fmt.Errorf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string)) } userinfo := rdata["result"].(map[string]interface{}) @@ -138,7 +138,7 @@ func (d *DingTalkAgent) GetUserIDByUnionID(unionid string) (string, error) { errcode := rdata["errcode"].(float64) if errcode != 0 { - return "", errors.New(fmt.Sprintf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string))) + return "", fmt.Errorf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string)) } result := rdata["result"].(map[string]interface{}) @@ -224,7 +224,7 @@ func (d *DingtalkQRLogin) GetUnionIDByCode(code string) (userid string, err erro } errcode := rdata["errcode"].(float64) if errcode != 0 { - return "", errors.New(fmt.Sprintf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string))) + return "", fmt.Errorf("登录错误: %.0f, %s", errcode, rdata["errmsg"].(string)) } unionid := rdata["user_info"].(map[string]interface{})["unionid"].(string) return unionid, nil diff --git a/utils/requests/requests.go b/utils/requests/requests.go index 65cf2476..34801f7f 100644 --- a/utils/requests/requests.go +++ b/utils/requests/requests.go @@ -5,7 +5,6 @@ import ( "net/http" "net/url" "os" - "errors" "fmt" ) @@ -39,7 +38,7 @@ func DownloadAndSaveFile(remoteUrl, dstFile string) (error) { if resp.StatusCode == http.StatusOK { _, err = io.Copy(out, resp.Body) }else{ - return errors.New(fmt.Sprintf("bad status: %s", resp.Status)) + return fmt.Errorf("bad status: %s", resp.Status) } return nil }