refactor: 更新项目引用路径从perfect-panel/ppanel-server到perfect-panel/server
feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGenerateCipher(t *testing.T) {
|
||||
pwd := GenerateCipher("serverKey", 128)
|
||||
pwd := GenerateCipher("", 16)
|
||||
t.Logf("pwd: %s", pwd)
|
||||
t.Logf("pwd length: %d", len(pwd))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -26,6 +27,16 @@ func ConvertValueToString(value reflect.Value) string {
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
case reflect.Struct, reflect.Map, reflect.Slice, reflect.Array:
|
||||
bytes, err := json.Marshal(value.Interface())
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling struct:", err.Error())
|
||||
return ""
|
||||
}
|
||||
if string(bytes) == "null" {
|
||||
return ""
|
||||
}
|
||||
return string(bytes)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
+33
-9
@@ -10,20 +10,31 @@ import (
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/constant"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
)
|
||||
|
||||
func DeepCopy[T, K interface{}](destStruct T, srcStruct K) T {
|
||||
// CopyOption 定义复制选项的函数类型
|
||||
type CopyOption func(*copier.Option)
|
||||
|
||||
// CopyWithIgnoreEmpty 设置是否忽略空值
|
||||
func CopyWithIgnoreEmpty(ignoreEmpty bool) CopyOption {
|
||||
return func(o *copier.Option) {
|
||||
o.IgnoreEmpty = ignoreEmpty
|
||||
}
|
||||
}
|
||||
|
||||
func DeepCopy[T, K any](destStruct T, srcStruct K, opts ...CopyOption) T {
|
||||
var dst = destStruct
|
||||
var src = srcStruct
|
||||
_ = copier.CopyWithOption(dst, src, copier.Option{
|
||||
|
||||
option := copier.Option{
|
||||
DeepCopy: true,
|
||||
IgnoreEmpty: true,
|
||||
Converters: []copier.TypeConverter{
|
||||
{
|
||||
SrcType: time.Time{},
|
||||
DstType: constant.Int64,
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
Fn: func(src any) (any, error) {
|
||||
s, ok := src.(time.Time)
|
||||
if !ok {
|
||||
return nil, errors.New("src type not matching")
|
||||
@@ -32,13 +43,21 @@ func DeepCopy[T, K interface{}](destStruct T, srcStruct K) T {
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(&option)
|
||||
}
|
||||
|
||||
_ = copier.CopyWithOption(dst, src, option)
|
||||
return dst
|
||||
}
|
||||
func ShallowCopy[T, K interface{}](destStruct T, srcStruct K) T {
|
||||
|
||||
func ShallowCopy[T, K interface{}](destStruct T, srcStruct K, opts ...CopyOption) T {
|
||||
var dst = destStruct
|
||||
var src = srcStruct
|
||||
_ = copier.CopyWithOption(dst, src, copier.Option{
|
||||
|
||||
option := copier.Option{
|
||||
IgnoreEmpty: true,
|
||||
Converters: []copier.TypeConverter{
|
||||
{
|
||||
@@ -46,7 +65,6 @@ func ShallowCopy[T, K interface{}](destStruct T, srcStruct K) T {
|
||||
DstType: constant.Int64,
|
||||
Fn: func(src interface{}) (interface{}, error) {
|
||||
s, ok := src.(time.Time)
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("src type not matching")
|
||||
}
|
||||
@@ -54,7 +72,13 @@ func ShallowCopy[T, K interface{}](destStruct T, srcStruct K) T {
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(&option)
|
||||
}
|
||||
|
||||
_ = copier.CopyWithOption(dst, src, option)
|
||||
return dst
|
||||
}
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ package tool
|
||||
import "testing"
|
||||
|
||||
func TestEncodePassWord(t *testing.T) {
|
||||
t.Logf("EncodePassWord: %v", EncodePassWord(""))
|
||||
t.Logf("EncodePassWord: %v", EncodePassWord("password"))
|
||||
}
|
||||
|
||||
+13
-1
@@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
func Int64SliceToStringSlice(slice []int64) []string {
|
||||
@@ -59,6 +59,7 @@ func Int64SliceToString(intSlice []int64) string {
|
||||
|
||||
// string slice to string
|
||||
func StringSliceToString(stringSlice []string) string {
|
||||
stringSlice = RemoveDuplicateElements(stringSlice...)
|
||||
return strings.Join(stringSlice, ",")
|
||||
}
|
||||
|
||||
@@ -128,3 +129,14 @@ func Contains[T comparable](slice []T, target T) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveStringElement 移除指定元素
|
||||
func RemoveStringElement(arr []string, element ...string) []string {
|
||||
var result []string
|
||||
for _, str := range arr {
|
||||
if !Contains(element, str) {
|
||||
result = append(result, str)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/server/internal/model/system"
|
||||
)
|
||||
|
||||
func SystemConfigSliceReflectToStruct(slice []*system.System, structType any) {
|
||||
|
||||
+14
-1
@@ -3,7 +3,7 @@ package tool
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
func AddTime(unit string, quantity int64, baseTime ...time.Time) time.Time {
|
||||
@@ -138,3 +138,16 @@ func YearDiff(startTime, endTime time.Time) int {
|
||||
}
|
||||
return yearDiff
|
||||
}
|
||||
|
||||
func DayDiff(startTime, endTime time.Time) int64 {
|
||||
// 计算时间差
|
||||
duration := endTime.Sub(startTime)
|
||||
return int64(duration.Hours() / 24) // 转换为整天数
|
||||
}
|
||||
|
||||
// HourDiff 计算两个时间点之间的小时差
|
||||
func HourDiff(startTime, endTime time.Time) int64 {
|
||||
// 计算时间差
|
||||
duration := endTime.Sub(startTime)
|
||||
return int64(duration.Hours()) // 返回小时数,可能包含小数部分
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package tool
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/constant"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
)
|
||||
|
||||
func TestExtractVersionNumber(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user