فهرست منبع

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

Signed-off-by: guoguangwu <[email protected]>
guangwu 2 سال پیش
والد
کامیت
06e7b0ab70
4فایلهای تغییر یافته به همراه6 افزوده شده و 8 حذف شده
  1. 0 1
      commands/command.go
  2. 1 1
      models/Member.go
  3. 4 4
      utils/dingtalk/dingtalk.go
  4. 1 2
      utils/requests/requests.go

+ 0 - 1
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"

+ 1 - 1
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配置

+ 4 - 4
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

+ 1 - 2
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
 }