mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: 组件升级、代码优化
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"mayfly-go/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func InitTokenConfig() {
|
||||
|
||||
54
server/pkg/utils/any.go
Normal file
54
server/pkg/utils/any.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// any类型转换为string, 如果any为nil则返回空字符串
|
||||
func Any2String(val any) string {
|
||||
if value, ok := val.(string); !ok {
|
||||
return ""
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
// any类型转换为int(可将字符串或int64转换), 如果any为nil则返回0
|
||||
func Any2Int(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)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// any类型转换为int64, 如果any为nil则返回0
|
||||
func Any2Int64(val any) int64 {
|
||||
if value, ok := val.(int64); !ok {
|
||||
return int64(Any2Int(val))
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package assert
|
||||
import "fmt"
|
||||
|
||||
// 断言条件为真,不满足的panic
|
||||
func IsTrue(condition bool, panicMsg string, params ...interface{}) {
|
||||
func IsTrue(condition bool, panicMsg string, params ...any) {
|
||||
if !condition {
|
||||
if len(params) != 0 {
|
||||
panic(fmt.Sprintf(panicMsg, params...))
|
||||
@@ -12,10 +12,10 @@ func IsTrue(condition bool, panicMsg string, params ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func State(condition bool, panicMsg string, params ...interface{}) {
|
||||
func State(condition bool, panicMsg string, params ...any) {
|
||||
IsTrue(condition, panicMsg, params...)
|
||||
}
|
||||
|
||||
func NotEmpty(str string, panicMsg string, params ...interface{}) {
|
||||
func NotEmpty(str string, panicMsg string, params ...any) {
|
||||
IsTrue(str != "", panicMsg, params...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user