style: 错误信息英文返回-framework模块
This commit is contained in:
@@ -90,7 +90,8 @@ func RateLimit(option LimitOption) gin.HandlerFunc {
|
|||||||
c.Header("X-RateLimit-Reset", fmt.Sprintf("%d", time.Now().Unix()+int64(rateTime))) // 重置时间戳
|
c.Header("X-RateLimit-Reset", fmt.Sprintf("%d", time.Now().Unix()+int64(rateTime))) // 重置时间戳
|
||||||
|
|
||||||
if rateCount >= option.Count {
|
if rateCount >= option.Count {
|
||||||
c.JSON(200, result.ErrMsg("访问过于频繁,请稍候再试"))
|
// 访问过于频繁,请稍候再试
|
||||||
|
c.JSON(200, result.ErrMsg("Visits are too frequent. Please try again later"))
|
||||||
c.Abort() // 停止执行后续的处理函数
|
c.Abort() // 停止执行后续的处理函数
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ func RepeatSubmit(interval int64) gin.HandlerFunc {
|
|||||||
|
|
||||||
// 小于间隔时间且参数内容一致
|
// 小于间隔时间且参数内容一致
|
||||||
if compareTime < interval && compareParams {
|
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()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,16 @@ func referer(c *gin.Context) {
|
|||||||
|
|
||||||
referer := c.GetHeader("Referer")
|
referer := c.GetHeader("Referer")
|
||||||
if referer == "" {
|
if referer == "" {
|
||||||
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer 未知"))
|
// 无效 Referer 未知
|
||||||
|
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer unknown"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取host
|
// 获取host
|
||||||
u, err := url.Parse(referer)
|
u, err := url.Parse(referer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer 未知"))
|
// 无效 Referer 未知
|
||||||
|
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer unknown"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
host := u.Host
|
host := u.Host
|
||||||
@@ -70,7 +72,8 @@ func referer(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
c.AbortWithStatusJSON(200, result.ErrMsg("无效 Referer "+host))
|
// 无效 Referer
|
||||||
|
c.AbortWithStatusJSON(200, result.ErrMsg("Invalid referer "+host))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func WriterCSVFile(data [][]string, filePath string) error {
|
|||||||
// 确保文件夹路径存在
|
// 确保文件夹路径存在
|
||||||
err := os.MkdirAll(dirPath, os.ModePerm)
|
err := os.MkdirAll(dirPath, os.ModePerm)
|
||||||
if err != nil {
|
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 文件
|
// 打开 CSV 文件
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("无法打开 CSV 文件:%v", err)
|
logger.Errorf("Open CSV file: %v", err)
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
@@ -62,7 +62,7 @@ func ReadCSVFile(filePath string) []map[string]string {
|
|||||||
// 读取 CSV 头部行
|
// 读取 CSV 头部行
|
||||||
header, err := reader.Read()
|
header, err := reader.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("无法读取 CSV 头部行:%v", err)
|
logger.Errorf("Read CSV header rows: %v", err)
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,13 @@ func generateFileName(fileName string) string {
|
|||||||
func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
|
func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
|
||||||
// 判断上传文件名称长度
|
// 判断上传文件名称长度
|
||||||
if len(fileName) > DEFAULT_FILE_NAME_LENGTH {
|
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()
|
maxFileSize := uploadFileSize()
|
||||||
if fileSize > maxFileSize {
|
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 {
|
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
|
return nil
|
||||||
@@ -107,7 +107,7 @@ func isAllowWrite(fileName string, allowExts []string, fileSize int64) error {
|
|||||||
func isAllowRead(filePath string) error {
|
func isAllowRead(filePath string) error {
|
||||||
// 禁止目录上跳级别
|
// 禁止目录上跳级别
|
||||||
if strings.Contains(filePath, "..") {
|
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 {
|
if !hasExt {
|
||||||
return fmt.Errorf("Rules for illegally downloaded files: %s", fileExt)
|
return fmt.Errorf("rules for illegally downloaded files: %s", fileExt)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ func init() {
|
|||||||
func RegionSearchByIp(ip string) (string, int, int64) {
|
func RegionSearchByIp(ip string) (string, int, int64) {
|
||||||
ip = ClientIP(ip)
|
ip = ClientIP(ip)
|
||||||
if ip == LOCAT_HOST {
|
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()
|
tStart := time.Now()
|
||||||
region, err := searcher.SearchByStr(ip)
|
region, err := searcher.SearchByStr(ip)
|
||||||
@@ -59,12 +60,12 @@ func RegionSearchByIp(ip string) (string, int, int64) {
|
|||||||
func RealAddressByIp(ip string) string {
|
func RealAddressByIp(ip string) string {
|
||||||
ip = ClientIP(ip)
|
ip = ClientIP(ip)
|
||||||
if ip == LOCAT_HOST {
|
if ip == LOCAT_HOST {
|
||||||
return "内网IP"
|
return "Intranet IP" // 内网IP
|
||||||
}
|
}
|
||||||
region, err := searcher.SearchByStr(ip)
|
region, err := searcher.SearchByStr(ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
|
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
|
||||||
return "未知"
|
return "unknown" // 未知
|
||||||
}
|
}
|
||||||
parts := strings.Split(region, "|")
|
parts := strings.Split(region, "|")
|
||||||
province := parts[2]
|
province := parts[2]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func FileSCPNeToLocal(neIp, nePath, localPath string) error {
|
|||||||
// 确保文件夹路径存在
|
// 确保文件夹路径存在
|
||||||
err := os.MkdirAll(dirPath, os.ModePerm)
|
err := os.MkdirAll(dirPath, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("创建文件夹失败 CreateFile %v", err)
|
log.Errorf("FileSCPNeToLocal MkdirAll err %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package token
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"ems.agt/src/framework/config"
|
"ems.agt/src/framework/config"
|
||||||
@@ -124,13 +124,14 @@ func Verify(tokenString string) (jwt.MapClaims, error) {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("token String Verify : %v", err)
|
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 {
|
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||||
return claims, nil
|
return claims, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("token valid error")
|
return nil, fmt.Errorf("token valid error")
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginUser 缓存的登录用户信息
|
// LoginUser 缓存的登录用户信息
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
|
|||||||
neType := c.Query("neType")
|
neType := c.Query("neType")
|
||||||
neId := c.Query("neId")
|
neId := c.Query("neId")
|
||||||
if neType == "" || neId == "" {
|
if neType == "" || neId == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user