style: 错误信息英文返回-framework模块

This commit is contained in:
TsMask
2023-11-08 15:00:05 +08:00
parent 267a13d3d6
commit 81138b8c22
9 changed files with 28 additions and 21 deletions

View File

@@ -90,7 +90,8 @@ func RateLimit(option LimitOption) gin.HandlerFunc {
c.Header("X-RateLimit-Reset", fmt.Sprintf("%d", time.Now().Unix()+int64(rateTime))) // 重置时间戳
if rateCount >= option.Count {
c.JSON(200, result.ErrMsg("访问过于频繁,请稍候再试"))
// 访问过于频繁,请稍候再试
c.JSON(200, result.ErrMsg("Visits are too frequent. Please try again later"))
c.Abort() // 停止执行后续的处理函数
return
}

View File

@@ -60,7 +60,8 @@ func RepeatSubmit(interval int64) gin.HandlerFunc {
// 小于间隔时间且参数内容一致
if compareTime < interval && compareParams {
c.JSON(200, result.ErrMsg("不允许重复提交,请稍候再试"))
// 不允许重复提交,请稍候再试
c.JSON(200, result.ErrMsg("Duplicate submissions are not allowed. Please try again later"))
c.Abort()
return
}

View File

@@ -42,14 +42,16 @@ func referer(c *gin.Context) {
referer := c.GetHeader("Referer")
if referer == "" {
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer 未知"))
// 无效 Referer 未知
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer unknown"))
return
}
// 获取host
u, err := url.Parse(referer)
if err != nil {
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer 未知"))
// 无效 Referer 未知
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer unknown"))
return
}
host := u.Host
@@ -70,7 +72,8 @@ func referer(c *gin.Context) {
}
}
if !ok {
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer "+host))
// 无效 Referer
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer "+host))
return
}
}

View File

@@ -22,7 +22,7 @@ func WriterCSVFile(data [][]string, filePath string) error {
// 确保文件夹路径存在
err := os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
logger.Errorf("创建文件夹失败 CreateFile %v", err)
logger.Errorf("MkdirAll dir %v", err)
}
// 创建或打开文件
@@ -51,7 +51,7 @@ func ReadCSVFile(filePath string) []map[string]string {
// 打开 CSV 文件
file, err := os.Open(filePath)
if err != nil {
logger.Errorf("无法打开 CSV 文件:%v", err)
logger.Errorf("Open CSV file: %v", err)
return arr
}
defer file.Close()
@@ -62,7 +62,7 @@ func ReadCSVFile(filePath string) []map[string]string {
// 读取 CSV 头部行
header, err := reader.Read()
if err != nil {
logger.Errorf("无法读取 CSV 头部行:%v", err)
logger.Errorf("Read CSV header rows: %v", err)
return arr
}

View File

@@ -73,13 +73,13 @@ func generateFileName(fileName string) string {
func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
// 判断上传文件名称长度
if len(fileName) > DEFAULT_FILE_NAME_LENGTH {
return fmt.Errorf("The maximum length limit for uploading file names is %d", DEFAULT_FILE_NAME_LENGTH)
return fmt.Errorf("the maximum length limit for uploading file names is %d", DEFAULT_FILE_NAME_LENGTH)
}
// 最大上传文件大小
maxFileSize := uploadFileSize()
if fileSize > maxFileSize {
return fmt.Errorf("Maximum upload file size %s", parse.Bit(float64(maxFileSize)))
return fmt.Errorf("maximum upload file size %s", parse.Bit(float64(maxFileSize)))
}
// 判断文件拓展是否为允许的拓展类型
@@ -95,7 +95,7 @@ func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
}
}
if !hasExt {
return fmt.Errorf("The upload file type is not supported, only the following types are supported:%s", strings.Join(allowExts, ","))
return fmt.Errorf("the upload file type is not supported, only the following types are supported: %s", strings.Join(allowExts, ","))
}
return nil
@@ -107,7 +107,7 @@ func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
func isAllowRead(filePath string) error {
// 禁止目录上跳级别
if strings.Contains(filePath, "..") {
return fmt.Errorf("Prohibit jumping levels on the directory")
return fmt.Errorf("prohibit jumping levels on the directory")
}
// 检查允许下载的文件规则
@@ -120,7 +120,7 @@ func isAllowRead(filePath string) error {
}
}
if !hasExt {
return fmt.Errorf("Rules for illegally downloaded files: %s", fileExt)
return fmt.Errorf("rules for illegally downloaded files: %s", fileExt)
}
return nil

View File

@@ -42,7 +42,8 @@ func init() {
func RegionSearchByIp(ip string) (string, int, int64) {
ip = ClientIP(ip)
if ip == LOCAT_HOST {
return "0|0|0|内网IP|内网IP", 0, 0
// "0|0|0|内网IP|内网IP"
return "0|0|0|Intranet IP|Intranet IP", 0, 0
}
tStart := time.Now()
region, err := searcher.SearchByStr(ip)
@@ -59,12 +60,12 @@ func RegionSearchByIp(ip string) (string, int, int64) {
func RealAddressByIp(ip string) string {
ip = ClientIP(ip)
if ip == LOCAT_HOST {
return "内网IP"
return "Intranet IP" // 内网IP
}
region, err := searcher.SearchByStr(ip)
if err != nil {
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
return "未知"
return "unknown" // 未知
}
parts := strings.Split(region, "|")
province := parts[2]

View File

@@ -32,7 +32,7 @@ func FileSCPNeToLocal(neIp, nePath, localPath string) error {
// 确保文件夹路径存在
err := os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
log.Errorf("创建文件夹失败 CreateFile %v", err)
log.Errorf("FileSCPNeToLocal MkdirAll err %v", err)
return err
}

View File

@@ -2,7 +2,7 @@ package token
import (
"encoding/json"
"errors"
"fmt"
"time"
"ems.agt/src/framework/config"
@@ -124,13 +124,14 @@ func Verify(tokenString string) (jwt.MapClaims, error) {
})
if err != nil {
logger.Errorf("token String Verify : %v", err)
return nil, errors.New("无效身份授权")
// 无效身份授权
return nil, fmt.Errorf("invalid identity authorization")
}
// 如果解析负荷成功并通过签名校验
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
return claims, nil
}
return nil, errors.New("token valid error")
return nil, fmt.Errorf("token valid error")
}
// LoginUser 缓存的登录用户信息

View File

@@ -26,7 +26,7 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
neType := c.Query("neType")
neId := c.Query("neId")
if neType == "" || neId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}