refactor: dbms与标签管理优化

This commit is contained in:
meilin.huang
2024-03-21 17:15:52 +08:00
parent b13d27ccd6
commit b2cfd1517c
43 changed files with 536 additions and 564 deletions

View File

@@ -13,6 +13,8 @@ import (
"net/http"
"os"
"time"
"github.com/may-fly/cast"
)
// 默认超时
@@ -131,7 +133,7 @@ func (r *RequestWrapper) PostMulipart(files []MultipartFile, reqParams collx.M)
}
// 如果有其他参数则写入body
for k, v := range reqParams {
if err := writer.WriteField(k, anyx.ConvString(v)); err != nil {
if err := writer.WriteField(k, cast.ToString(v)); err != nil {
return &ResponseWrapper{err: err}
}
}

View File

@@ -2,64 +2,10 @@ package anyx
import (
"encoding/json"
"math"
"reflect"
"strconv"
)
// any类型转换为string, 如果any为nil则返回空字符串
func ConvString(val any) string {
if value, ok := val.(string); !ok {
return ""
} else {
return value
}
}
// any类型转换为int可将字符串或int64转换, 如果any为nil则返回0
func ConvInt(val any) int {
switch value := val.(type) {
case int:
return value
case string:
if intV, err := strconv.Atoi(value); err == nil {
return intV
}
case int64:
return int(value)
case uint64:
return int(value)
case int32:
return int(value)
case uint32:
return int(value)
case int16:
return int(value)
case uint16:
return int(value)
case int8:
return int(value)
case uint8:
return int(value)
case float32:
return int(value)
case float64:
return int(math.Round(value))
default:
return 0
}
return 0
}
// any类型转换为int64, 如果any为nil则返回0
func ConvInt64(val any) int64 {
if value, ok := val.(int64); !ok {
return int64(ConvInt(val))
} else {
return value
}
}
func IsBlank(value any) bool {
if value == nil {
return true

View File

@@ -1,19 +0,0 @@
package conv
import (
"mayfly-go/pkg/logx"
"strconv"
)
// 将字符串值转为int值, 若value为空或者转换失败则返回默认值
func Str2Int(value string, defaultValue int) int {
if value == "" {
return defaultValue
}
if intV, err := strconv.Atoi(value); err != nil {
logx.ErrorTrace("str conv int error: ", err)
return defaultValue
} else {
return intV
}
}