Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) #878

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion models/Member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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配置
Expand Down
8 changes: 4 additions & 4 deletions utils/dingtalk/dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions utils/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"net/url"
"os"
"errors"
"fmt"
)

Expand Down Expand Up @@ -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
}