Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
273e63e8
提交
273e63e8
authored
11月 18, 2025
作者:
mooncake
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
639f55d7
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
210 行增加
和
125 行删除
+210
-125
consul.go
config/consul.go
+1
-1
local.go
config/local.go
+4
-3
database.go
database/database.go
+2
-2
response.go
gin/response/response.go
+4
-2
memory.go
pkg/cache/memory.go
+10
-10
redis.go
pkg/cache/redis.go
+29
-29
captcha.go
pkg/captcha/captcha.go
+2
-1
email.go
pkg/email/email.go
+2
-2
oss.go
pkg/oss/oss.go
+5
-5
mysql.go
pkg/sgorm/mysql/mysql.go
+6
-6
query_condition.go
pkg/sgorm/query/query_condition.go
+8
-8
ws.go
pkg/ws/ws.go
+3
-3
xerror_api.go
pkg/xerrors/xerror/xerror_api.go
+85
-12
xerror_error.go
pkg/xerrors/xerror/xerror_error.go
+8
-0
xerror_z_bench_test.go
pkg/xerrors/xerror/xerror_z_bench_test.go
+1
-1
xerror_z_example_test.go
pkg/xerrors/xerror/xerror_z_example_test.go
+1
-1
xerror_z_unit_test.go
pkg/xerrors/xerror/xerror_z_unit_test.go
+17
-17
ocache.go
xcommon/ocache/ocache.go
+7
-7
odao.go
xcommon/odao/odao.go
+1
-1
cron_job.go
xcron/dao/cron_job.go
+1
-1
cron_job.go
xcron/service/cron_job.go
+2
-2
go.go
xutils/goutils/go.go
+2
-2
json.go
xutils/jsonutils/json.go
+1
-1
red_sync_utils.go
xutils/redsyncutils/red_sync_utils.go
+3
-3
xslice.go
xutils/sliceutils/xslice.go
+2
-2
wg.go
xutils/wg/wg.go
+2
-2
xsf.go
xutils/xsf/xsf.go
+1
-1
没有找到文件。
config/consul.go
浏览文件 @
273e63e8
...
@@ -50,7 +50,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher {
...
@@ -50,7 +50,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher {
return
x
return
x
}
}
if
kv
==
nil
||
len
(
kv
.
Value
)
==
0
{
if
kv
==
nil
||
len
(
kv
.
Value
)
==
0
{
x
.
err
=
xerror
.
New
(
"[consul]请先配置consul"
)
x
.
err
=
xerror
.
New
RuntimeError
(
"[consul]请先配置consul"
)
return
x
return
x
}
}
if
hashutils
.
Md5
(
kv
.
Value
)
!=
hashutils
.
Md5
(
x
.
cfg
.
GetContent
())
{
if
hashutils
.
Md5
(
kv
.
Value
)
!=
hashutils
.
Md5
(
x
.
cfg
.
GetContent
())
{
...
...
config/local.go
浏览文件 @
273e63e8
...
@@ -7,12 +7,13 @@ import (
...
@@ -7,12 +7,13 @@ import (
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"os"
"os"
"path"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/fsnotify/fsnotify"
"github.com/fsnotify/fsnotify"
...
@@ -41,13 +42,13 @@ func (x *localParser) parseLocal(configFile string, obj ICfg, reloads ...func())
...
@@ -41,13 +42,13 @@ func (x *localParser) parseLocal(configFile string, obj ICfg, reloads ...func())
viper
.
SetConfigName
(
filename
)
// file name
viper
.
SetConfigName
(
filename
)
// file name
viper
.
SetConfigType
(
ext
)
// get the configuration type from the file name
viper
.
SetConfigType
(
ext
)
// get the configuration type from the file name
if
err
=
viper
.
ReadInConfig
();
err
!=
nil
{
if
err
=
viper
.
ReadInConfig
();
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
obj
.
Lock
()
obj
.
Lock
()
if
err
=
viper
.
Unmarshal
(
obj
);
err
!=
nil
{
if
err
=
viper
.
Unmarshal
(
obj
);
err
!=
nil
{
obj
.
Unlock
()
obj
.
Unlock
()
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
obj
.
Unlock
()
obj
.
Unlock
()
...
...
database/database.go
浏览文件 @
273e63e8
...
@@ -35,7 +35,7 @@ func InitDB() (err error) {
...
@@ -35,7 +35,7 @@ func InitDB() (err error) {
}
}
gdbs
[
db
.
Name
]
=
gdb
gdbs
[
db
.
Name
]
=
gdb
default
:
default
:
return
xerror
.
New
(
"InitDB error, please modify the correct 'database' configuration at yaml file. "
+
return
xerror
.
New
RuntimeError
(
"InitDB error, please modify the correct 'database' configuration at yaml file. "
+
"Refer to https://xmall/blob/main/configs/xmall.yml#L85"
)
"Refer to https://xmall/blob/main/configs/xmall.yml#L85"
)
}
}
}
}
...
@@ -60,7 +60,7 @@ func (x XDB) DB() *sgorm.DB {
...
@@ -60,7 +60,7 @@ func (x XDB) DB() *sgorm.DB {
func
DB
(
name
string
)
*
sgorm
.
DB
{
func
DB
(
name
string
)
*
sgorm
.
DB
{
conn
,
ok
:=
gdbs
[
name
]
conn
,
ok
:=
gdbs
[
name
]
if
!
ok
{
if
!
ok
{
err
:=
xerror
.
Newf
(
"database[%s] not initialized"
,
name
)
err
:=
xerror
.
New
RuntimeError
f
(
"database[%s] not initialized"
,
name
)
panic
(
err
)
panic
(
err
)
}
}
return
conn
return
conn
...
...
gin/response/response.go
浏览文件 @
273e63e8
...
@@ -269,9 +269,11 @@ func Error(c *gin.Context, err error) {
...
@@ -269,9 +269,11 @@ func Error(c *gin.Context, err error) {
msg
:=
""
msg
:=
""
if
err
!=
nil
{
if
err
!=
nil
{
switch
e
:=
err
.
(
type
)
{
switch
e
:=
err
.
(
type
)
{
case
*
xerror
.
BizError
,
*
xerror
.
ParamError
:
case
*
xerror
.
BizError
,
*
xerror
.
ParamError
:
//无需打印日志,在[middleware][logging]里会打印
msg
=
e
.
Error
()
msg
=
e
.
Error
()
case
*
xerror
.
DBError
,
*
xerror
.
NetError
:
case
*
xerror
.
DBError
:
// 无需打印日志,在gorm层会打印日志
msg
=
"网络开小差了,请稍后再试~"
case
*
xerror
.
NetError
,
*
xerror
.
CacheError
,
*
xerror
.
RuntimeError
:
// 需要打印日志
logger
.
Error
(
fmt
.
Sprintf
(
"[response]%s"
,
err
.
Error
()),
ctxutils
.
GinTraceIDField
(
c
))
logger
.
Error
(
fmt
.
Sprintf
(
"[response]%s"
,
err
.
Error
()),
ctxutils
.
GinTraceIDField
(
c
))
msg
=
"网络开小差了,请稍后再试~"
msg
=
"网络开小差了,请稍后再试~"
default
:
default
:
...
...
pkg/cache/memory.go
浏览文件 @
273e63e8
...
@@ -41,14 +41,14 @@ const logPrefix = "[memory]"
...
@@ -41,14 +41,14 @@ const logPrefix = "[memory]"
func
(
m
*
memoryCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
func
(
m
*
memoryCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
buf
,
err
:=
encoding
.
Marshal
(
m
.
encoding
,
val
)
buf
,
err
:=
encoding
.
Marshal
(
m
.
encoding
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
return
xerror
.
NewCache
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
}
}
if
len
(
buf
)
==
0
{
if
len
(
buf
)
==
0
{
buf
=
NotFoundPlaceholderBytes
buf
=
NotFoundPlaceholderBytes
}
}
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
st
:=
time
.
Now
()
st
:=
time
.
Now
()
ok
:=
m
.
client
.
SetWithTTL
(
cacheKey
,
buf
,
0
,
expiration
)
ok
:=
m
.
client
.
SetWithTTL
(
cacheKey
,
buf
,
0
,
expiration
)
...
@@ -60,7 +60,7 @@ func (m *memoryCache) Set(ctx context.Context, key string, val any, expiration t
...
@@ -60,7 +60,7 @@ func (m *memoryCache) Set(ctx context.Context, key string, val any, expiration t
logger
.
Any
(
"expiration"
,
expiration
.
String
()),
logger
.
Any
(
"expiration"
,
expiration
.
String
()),
ctxUtil
.
CtxTraceIDField
(
ctx
))
ctxUtil
.
CtxTraceIDField
(
ctx
))
if
!
ok
{
if
!
ok
{
return
xerror
.
New
(
"SetWithTTL failed"
)
return
xerror
.
New
CacheError
(
"SetWithTTL failed"
)
}
}
return
nil
return
nil
...
@@ -76,7 +76,7 @@ func isSuccess(result bool) string {
...
@@ -76,7 +76,7 @@ func isSuccess(result bool) string {
func
(
m
*
memoryCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
func
(
m
*
memoryCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
0
,
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
v
,
ok
:=
m
.
client
.
Get
(
cacheKey
)
v
,
ok
:=
m
.
client
.
Get
(
cacheKey
)
if
!
ok
{
if
!
ok
{
...
@@ -99,7 +99,7 @@ func (m *memoryCache) IncrBy(ctx context.Context, key string, val int64) (int64,
...
@@ -99,7 +99,7 @@ func (m *memoryCache) IncrBy(ctx context.Context, key string, val int64) (int64,
func
(
m
*
memoryCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
func
(
m
*
memoryCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
st
:=
time
.
Now
()
st
:=
time
.
Now
()
...
@@ -115,7 +115,7 @@ func (m *memoryCache) Get(ctx context.Context, key string, val any) error {
...
@@ -115,7 +115,7 @@ func (m *memoryCache) Get(ctx context.Context, key string, val any) error {
dataBytes
,
ok
:=
data
.
([]
byte
)
dataBytes
,
ok
:=
data
.
([]
byte
)
if
!
ok
{
if
!
ok
{
return
xerror
.
Errorf
(
"data type error, key=%s, type=%T"
,
key
,
data
)
return
xerror
.
NewCache
Errorf
(
"data type error, key=%s, type=%T"
,
key
,
data
)
}
}
if
len
(
dataBytes
)
==
0
||
bytes
.
Equal
(
dataBytes
,
NotFoundPlaceholderBytes
)
{
if
len
(
dataBytes
)
==
0
||
bytes
.
Equal
(
dataBytes
,
NotFoundPlaceholderBytes
)
{
logger
.
Info
(
fmt
.
Sprintf
(
"%s get"
,
logPrefix
),
logger
.
Info
(
fmt
.
Sprintf
(
"%s get"
,
logPrefix
),
...
@@ -129,7 +129,7 @@ func (m *memoryCache) Get(ctx context.Context, key string, val any) error {
...
@@ -129,7 +129,7 @@ func (m *memoryCache) Get(ctx context.Context, key string, val any) error {
err
=
encoding
.
Unmarshal
(
m
.
encoding
,
dataBytes
,
val
)
err
=
encoding
.
Unmarshal
(
m
.
encoding
,
dataBytes
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, data=%s "
,
return
xerror
.
NewCache
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, data=%s "
,
err
,
key
,
cacheKey
,
val
,
dataBytes
)
err
,
key
,
cacheKey
,
val
,
dataBytes
)
}
}
logger
.
Info
(
fmt
.
Sprintf
(
"%s get"
,
logPrefix
),
logger
.
Info
(
fmt
.
Sprintf
(
"%s get"
,
logPrefix
),
...
@@ -150,7 +150,7 @@ func (m *memoryCache) Del(ctx context.Context, keys ...string) error {
...
@@ -150,7 +150,7 @@ func (m *memoryCache) Del(ctx context.Context, keys ...string) error {
for
_
,
key
:=
range
keys
{
for
_
,
key
:=
range
keys
{
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"build cache key error, err=%v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"build cache key error, err=%v, key=%s"
,
err
,
key
)
}
}
st
:=
time
.
Now
()
st
:=
time
.
Now
()
m
.
client
.
Del
(
cacheKey
)
m
.
client
.
Del
(
cacheKey
)
...
@@ -208,12 +208,12 @@ func (m *memoryCache) MGet(ctx context.Context, keys []string) ([]any, error) {
...
@@ -208,12 +208,12 @@ func (m *memoryCache) MGet(ctx context.Context, keys []string) ([]any, error) {
func
(
m
*
memoryCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
func
(
m
*
memoryCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
m
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
st
:=
time
.
Now
()
st
:=
time
.
Now
()
ok
:=
m
.
client
.
SetWithTTL
(
cacheKey
,
[]
byte
(
NotFoundPlaceholder
),
0
,
DefaultNotFoundExpireTime
)
ok
:=
m
.
client
.
SetWithTTL
(
cacheKey
,
[]
byte
(
NotFoundPlaceholder
),
0
,
DefaultNotFoundExpireTime
)
if
!
ok
{
if
!
ok
{
return
xerror
.
New
(
"SetWithTTL failed"
)
return
xerror
.
New
CacheError
(
"SetWithTTL failed"
)
}
}
logger
.
Info
(
fmt
.
Sprintf
(
"%s set"
,
logPrefix
),
logger
.
Info
(
fmt
.
Sprintf
(
"%s set"
,
logPrefix
),
logger
.
Any
(
"result"
,
isSuccess
(
ok
)),
logger
.
Any
(
"result"
,
isSuccess
(
ok
)),
...
...
pkg/cache/redis.go
浏览文件 @
273e63e8
...
@@ -39,11 +39,11 @@ func NewRedisCache(client *redis.Client, keyPrefix string, encode encoding.Encod
...
@@ -39,11 +39,11 @@ func NewRedisCache(client *redis.Client, keyPrefix string, encode encoding.Encod
func
(
c
*
redisCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
func
(
c
*
redisCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
0
,
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cur
,
err
:=
c
.
client
.
IncrBy
(
ctx
,
cacheKey
,
val
)
.
Result
()
cur
,
err
:=
c
.
client
.
IncrBy
(
ctx
,
cacheKey
,
val
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
return
0
,
xerror
.
NewCache
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
}
}
return
cur
,
nil
return
cur
,
nil
}
}
...
@@ -52,12 +52,12 @@ func (c *redisCache) IncrBy(ctx context.Context, key string, val int64) (int64,
...
@@ -52,12 +52,12 @@ func (c *redisCache) IncrBy(ctx context.Context, key string, val int64) (int64,
func
(
c
*
redisCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
func
(
c
*
redisCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
buf
,
err
:=
encoding
.
Marshal
(
c
.
encoding
,
val
)
buf
,
err
:=
encoding
.
Marshal
(
c
.
encoding
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
return
xerror
.
NewCache
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
}
}
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
//if expiration == 0 {
//if expiration == 0 {
// expiration = DefaultExpireTime
// expiration = DefaultExpireTime
...
@@ -67,7 +67,7 @@ func (c *redisCache) Set(ctx context.Context, key string, val any, expiration ti
...
@@ -67,7 +67,7 @@ func (c *redisCache) Set(ctx context.Context, key string, val any, expiration ti
}
}
err
=
c
.
client
.
Set
(
ctx
,
cacheKey
,
buf
,
expiration
)
.
Err
()
err
=
c
.
client
.
Set
(
ctx
,
cacheKey
,
buf
,
expiration
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
return
xerror
.
NewCache
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
}
}
return
nil
return
nil
}
}
...
@@ -76,7 +76,7 @@ func (c *redisCache) Set(ctx context.Context, key string, val any, expiration ti
...
@@ -76,7 +76,7 @@ func (c *redisCache) Set(ctx context.Context, key string, val any, expiration ti
func
(
c
*
redisCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
func
(
c
*
redisCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
dataBytes
,
err
:=
c
.
client
.
Get
(
ctx
,
cacheKey
)
.
Bytes
()
dataBytes
,
err
:=
c
.
client
.
Get
(
ctx
,
cacheKey
)
.
Bytes
()
...
@@ -92,7 +92,7 @@ func (c *redisCache) Get(ctx context.Context, key string, val any) error {
...
@@ -92,7 +92,7 @@ func (c *redisCache) Get(ctx context.Context, key string, val any) error {
}
}
err
=
encoding
.
Unmarshal
(
c
.
encoding
,
dataBytes
,
val
)
err
=
encoding
.
Unmarshal
(
c
.
encoding
,
dataBytes
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s "
,
return
xerror
.
NewCache
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s "
,
err
,
key
,
cacheKey
,
val
,
dataBytes
)
err
,
key
,
cacheKey
,
val
,
dataBytes
)
}
}
return
nil
return
nil
...
@@ -126,7 +126,7 @@ func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]any, expi
...
@@ -126,7 +126,7 @@ func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]any, expi
pipeline
:=
c
.
client
.
Pipeline
()
pipeline
:=
c
.
client
.
Pipeline
()
err
:=
pipeline
.
MSet
(
ctx
,
paris
...
)
.
Err
()
err
:=
pipeline
.
MSet
(
ctx
,
paris
...
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"pipeline.MSet error: %v"
,
err
)
return
xerror
.
NewCache
Errorf
(
"pipeline.MSet error: %v"
,
err
)
}
}
for
i
:=
0
;
i
<
len
(
paris
);
i
=
i
+
2
{
for
i
:=
0
;
i
<
len
(
paris
);
i
=
i
+
2
{
switch
paris
[
i
]
.
(
type
)
{
switch
paris
[
i
]
.
(
type
)
{
...
@@ -138,7 +138,7 @@ func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]any, expi
...
@@ -138,7 +138,7 @@ func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]any, expi
}
}
_
,
err
=
pipeline
.
Exec
(
ctx
)
_
,
err
=
pipeline
.
Exec
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"pipeline.Exec error: %v"
,
err
)
return
xerror
.
NewCache
Errorf
(
"pipeline.Exec error: %v"
,
err
)
}
}
return
nil
return
nil
}
}
...
@@ -152,13 +152,13 @@ func (c *redisCache) MultiGet(ctx context.Context, keys []string, value any) err
...
@@ -152,13 +152,13 @@ func (c *redisCache) MultiGet(ctx context.Context, keys []string, value any) err
for
index
,
key
:=
range
keys
{
for
index
,
key
:=
range
keys
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cacheKeys
[
index
]
=
cacheKey
cacheKeys
[
index
]
=
cacheKey
}
}
values
,
err
:=
c
.
client
.
MGet
(
ctx
,
cacheKeys
...
)
.
Result
()
values
,
err
:=
c
.
client
.
MGet
(
ctx
,
cacheKeys
...
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.MGet error: %v, keys=%+v"
,
err
,
cacheKeys
)
return
xerror
.
NewCache
Errorf
(
"c.client.MGet error: %v, keys=%+v"
,
err
,
cacheKeys
)
}
}
// Injection into map via reflection
// Injection into map via reflection
...
@@ -191,7 +191,7 @@ func (c *redisCache) MGet(ctx context.Context, keys []string) ([]any, error) {
...
@@ -191,7 +191,7 @@ func (c *redisCache) MGet(ctx context.Context, keys []string) ([]any, error) {
for
index
,
key
:=
range
keys
{
for
index
,
key
:=
range
keys
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
nil
,
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cacheKeys
[
index
]
=
cacheKey
cacheKeys
[
index
]
=
cacheKey
}
}
...
@@ -214,7 +214,7 @@ func (c *redisCache) Del(ctx context.Context, keys ...string) error {
...
@@ -214,7 +214,7 @@ func (c *redisCache) Del(ctx context.Context, keys ...string) error {
}
}
err
:=
c
.
client
.
Del
(
ctx
,
cacheKeys
...
)
.
Err
()
err
:=
c
.
client
.
Del
(
ctx
,
cacheKeys
...
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.Del error: %v, keys=%+v"
,
err
,
cacheKeys
)
return
xerror
.
NewCache
Errorf
(
"c.client.Del error: %v, keys=%+v"
,
err
,
cacheKeys
)
}
}
return
nil
return
nil
}
}
...
@@ -223,7 +223,7 @@ func (c *redisCache) Del(ctx context.Context, keys ...string) error {
...
@@ -223,7 +223,7 @@ func (c *redisCache) Del(ctx context.Context, keys ...string) error {
func
(
c
*
redisCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
func
(
c
*
redisCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
return
c
.
client
.
Set
(
ctx
,
cacheKey
,
NotFoundPlaceholder
,
DefaultNotFoundExpireTime
)
.
Err
()
return
c
.
client
.
Set
(
ctx
,
cacheKey
,
NotFoundPlaceholder
,
DefaultNotFoundExpireTime
)
.
Err
()
...
@@ -232,7 +232,7 @@ func (c *redisCache) SetCacheWithNotFound(ctx context.Context, key string) error
...
@@ -232,7 +232,7 @@ func (c *redisCache) SetCacheWithNotFound(ctx context.Context, key string) error
// BuildCacheKey construct a cache key with a prefix
// BuildCacheKey construct a cache key with a prefix
func
BuildCacheKey
(
keyPrefix
string
,
key
string
)
(
string
,
error
)
{
func
BuildCacheKey
(
keyPrefix
string
,
key
string
)
(
string
,
error
)
{
if
key
==
""
{
if
key
==
""
{
return
""
,
xerror
.
New
(
"[cache] key should not be empty"
)
return
""
,
xerror
.
New
CacheError
(
"[cache] key should not be empty"
)
}
}
cacheKey
:=
key
cacheKey
:=
key
...
@@ -268,12 +268,12 @@ func NewRedisClusterCache(client *redis.ClusterClient, keyPrefix string, encode
...
@@ -268,12 +268,12 @@ func NewRedisClusterCache(client *redis.ClusterClient, keyPrefix string, encode
func
(
c
*
redisClusterCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
func
(
c
*
redisClusterCache
)
Set
(
ctx
context
.
Context
,
key
string
,
val
any
,
expiration
time
.
Duration
)
error
{
buf
,
err
:=
encoding
.
Marshal
(
c
.
encoding
,
val
)
buf
,
err
:=
encoding
.
Marshal
(
c
.
encoding
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
return
xerror
.
NewCache
Errorf
(
"encoding.Marshal error: %v, key=%s, val=%+v "
,
err
,
key
,
val
)
}
}
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
//if expiration == 0 {
//if expiration == 0 {
// expiration = DefaultExpireTime
// expiration = DefaultExpireTime
...
@@ -283,7 +283,7 @@ func (c *redisClusterCache) Set(ctx context.Context, key string, val any, expira
...
@@ -283,7 +283,7 @@ func (c *redisClusterCache) Set(ctx context.Context, key string, val any, expira
}
}
err
=
c
.
client
.
Set
(
ctx
,
cacheKey
,
buf
,
expiration
)
.
Err
()
err
=
c
.
client
.
Set
(
ctx
,
cacheKey
,
buf
,
expiration
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
return
xerror
.
NewCache
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
}
}
return
nil
return
nil
}
}
...
@@ -291,11 +291,11 @@ func (c *redisClusterCache) Set(ctx context.Context, key string, val any, expira
...
@@ -291,11 +291,11 @@ func (c *redisClusterCache) Set(ctx context.Context, key string, val any, expira
func
(
c
*
redisClusterCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
func
(
c
*
redisClusterCache
)
IncrBy
(
ctx
context
.
Context
,
key
string
,
val
int64
)
(
int64
,
error
)
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
0
,
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cur
,
err
:=
c
.
client
.
IncrBy
(
ctx
,
cacheKey
,
val
)
.
Result
()
cur
,
err
:=
c
.
client
.
IncrBy
(
ctx
,
cacheKey
,
val
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
return
0
,
xerror
.
NewCache
Errorf
(
"c.client.Set error: %v, cacheKey=%s"
,
err
,
cacheKey
)
}
}
return
cur
,
nil
return
cur
,
nil
}
}
...
@@ -304,7 +304,7 @@ func (c *redisClusterCache) IncrBy(ctx context.Context, key string, val int64) (
...
@@ -304,7 +304,7 @@ func (c *redisClusterCache) IncrBy(ctx context.Context, key string, val int64) (
func
(
c
*
redisClusterCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
func
(
c
*
redisClusterCache
)
Get
(
ctx
context
.
Context
,
key
string
,
val
any
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
dataBytes
,
err
:=
c
.
client
.
Get
(
ctx
,
cacheKey
)
.
Bytes
()
dataBytes
,
err
:=
c
.
client
.
Get
(
ctx
,
cacheKey
)
.
Bytes
()
...
@@ -320,7 +320,7 @@ func (c *redisClusterCache) Get(ctx context.Context, key string, val any) error
...
@@ -320,7 +320,7 @@ func (c *redisClusterCache) Get(ctx context.Context, key string, val any) error
}
}
err
=
encoding
.
Unmarshal
(
c
.
encoding
,
dataBytes
,
val
)
err
=
encoding
.
Unmarshal
(
c
.
encoding
,
dataBytes
,
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s "
,
return
xerror
.
NewCache
Errorf
(
"encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s "
,
err
,
key
,
cacheKey
,
val
,
dataBytes
)
err
,
key
,
cacheKey
,
val
,
dataBytes
)
}
}
return
nil
return
nil
...
@@ -350,7 +350,7 @@ func (c *redisClusterCache) MultiSet(ctx context.Context, valueMap map[string]an
...
@@ -350,7 +350,7 @@ func (c *redisClusterCache) MultiSet(ctx context.Context, valueMap map[string]an
pipeline
:=
c
.
client
.
Pipeline
()
pipeline
:=
c
.
client
.
Pipeline
()
err
:=
pipeline
.
MSet
(
ctx
,
paris
...
)
.
Err
()
err
:=
pipeline
.
MSet
(
ctx
,
paris
...
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"pipeline.MSet error: %v"
,
err
)
return
xerror
.
NewCache
Errorf
(
"pipeline.MSet error: %v"
,
err
)
}
}
for
i
:=
0
;
i
<
len
(
paris
);
i
=
i
+
2
{
for
i
:=
0
;
i
<
len
(
paris
);
i
=
i
+
2
{
switch
paris
[
i
]
.
(
type
)
{
switch
paris
[
i
]
.
(
type
)
{
...
@@ -362,7 +362,7 @@ func (c *redisClusterCache) MultiSet(ctx context.Context, valueMap map[string]an
...
@@ -362,7 +362,7 @@ func (c *redisClusterCache) MultiSet(ctx context.Context, valueMap map[string]an
}
}
_
,
err
=
pipeline
.
Exec
(
ctx
)
_
,
err
=
pipeline
.
Exec
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"pipeline.Exec error: %v"
,
err
)
return
xerror
.
NewCache
Errorf
(
"pipeline.Exec error: %v"
,
err
)
}
}
return
nil
return
nil
}
}
...
@@ -376,13 +376,13 @@ func (c *redisClusterCache) MultiGet(ctx context.Context, keys []string, value a
...
@@ -376,13 +376,13 @@ func (c *redisClusterCache) MultiGet(ctx context.Context, keys []string, value a
for
index
,
key
:=
range
keys
{
for
index
,
key
:=
range
keys
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cacheKeys
[
index
]
=
cacheKey
cacheKeys
[
index
]
=
cacheKey
}
}
values
,
err
:=
c
.
client
.
MGet
(
ctx
,
cacheKeys
...
)
.
Result
()
values
,
err
:=
c
.
client
.
MGet
(
ctx
,
cacheKeys
...
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.MGet error: %v, keys=%+v"
,
err
,
cacheKeys
)
return
xerror
.
NewCache
Errorf
(
"c.client.MGet error: %v, keys=%+v"
,
err
,
cacheKeys
)
}
}
// Injection into map via reflection
// Injection into map via reflection
...
@@ -414,7 +414,7 @@ func (c *redisClusterCache) MGet(ctx context.Context, keys []string) ([]any, err
...
@@ -414,7 +414,7 @@ func (c *redisClusterCache) MGet(ctx context.Context, keys []string) ([]any, err
for
index
,
key
:=
range
keys
{
for
index
,
key
:=
range
keys
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
nil
,
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
cacheKeys
[
index
]
=
cacheKey
cacheKeys
[
index
]
=
cacheKey
}
}
...
@@ -437,7 +437,7 @@ func (c *redisClusterCache) Del(ctx context.Context, keys ...string) error {
...
@@ -437,7 +437,7 @@ func (c *redisClusterCache) Del(ctx context.Context, keys ...string) error {
}
}
err
:=
c
.
client
.
Del
(
ctx
,
cacheKeys
...
)
.
Err
()
err
:=
c
.
client
.
Del
(
ctx
,
cacheKeys
...
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"c.client.Del error: %v, keys=%+v"
,
err
,
cacheKeys
)
return
xerror
.
NewCache
Errorf
(
"c.client.Del error: %v, keys=%+v"
,
err
,
cacheKeys
)
}
}
return
nil
return
nil
}
}
...
@@ -446,7 +446,7 @@ func (c *redisClusterCache) Del(ctx context.Context, keys ...string) error {
...
@@ -446,7 +446,7 @@ func (c *redisClusterCache) Del(ctx context.Context, keys ...string) error {
func
(
c
*
redisClusterCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
func
(
c
*
redisClusterCache
)
SetCacheWithNotFound
(
ctx
context
.
Context
,
key
string
)
error
{
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
cacheKey
,
err
:=
BuildCacheKey
(
c
.
KeyPrefix
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
return
xerror
.
NewCache
Errorf
(
"BuildCacheKey error: %v, key=%s"
,
err
,
key
)
}
}
return
c
.
client
.
Set
(
ctx
,
cacheKey
,
NotFoundPlaceholder
,
DefaultNotFoundExpireTime
)
.
Err
()
return
c
.
client
.
Set
(
ctx
,
cacheKey
,
NotFoundPlaceholder
,
DefaultNotFoundExpireTime
)
.
Err
()
...
...
pkg/captcha/captcha.go
浏览文件 @
273e63e8
...
@@ -2,6 +2,7 @@ package captcha
...
@@ -2,6 +2,7 @@ package captcha
import
(
import
(
"context"
"context"
"fmt"
"strings"
"strings"
"time"
"time"
...
@@ -54,7 +55,7 @@ func (rs *RedisStore) Get(id string, clear bool) string {
...
@@ -54,7 +55,7 @@ func (rs *RedisStore) Get(id string, clear bool) string {
if
xerror
.
Is
(
err
,
redis
.
Nil
)
{
if
xerror
.
Is
(
err
,
redis
.
Nil
)
{
return
""
return
""
}
}
panic
(
xerror
.
New
(
err
.
Error
()))
fmt
.
Println
(
xerror
.
NewNetError
(
err
.
Error
()))
}
}
if
clear
{
if
clear
{
go
rs
.
client
.
Del
(
ctx
,
key
)
go
rs
.
client
.
Del
(
ctx
,
key
)
...
...
pkg/email/email.go
浏览文件 @
273e63e8
...
@@ -114,7 +114,7 @@ func SendTLS(ctx context.Context, e *config.Email) error {
...
@@ -114,7 +114,7 @@ func SendTLS(ctx context.Context, e *config.Email) error {
}
}
d
.
SSL
=
true
d
.
SSL
=
true
if
err
:=
d
.
DialAndSend
(
m
);
err
!=
nil
{
if
err
:=
d
.
DialAndSend
(
m
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
NetError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
@@ -232,7 +232,7 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
...
@@ -232,7 +232,7 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
}
}
return
nil
return
nil
});
err
!=
nil
{
});
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
NetError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
pkg/oss/oss.go
浏览文件 @
273e63e8
...
@@ -28,7 +28,7 @@ func NewClient(cfg *AliOssConfig) (bucket *oss.Bucket, err error) {
...
@@ -28,7 +28,7 @@ func NewClient(cfg *AliOssConfig) (bucket *oss.Bucket, err error) {
// client, err := oss.New(cfg.Endpoint, cfg.AccessKeyId, cfg.AccessKeySecret, oss.AuthVersion(oss.AuthV4), oss.Region(cfg.Region))
// client, err := oss.New(cfg.Endpoint, cfg.AccessKeyId, cfg.AccessKeySecret, oss.AuthVersion(oss.AuthV4), oss.Region(cfg.Region))
client
,
err
:=
oss
.
New
(
cfg
.
Endpoint
,
cfg
.
AccessKeyId
,
cfg
.
AccessKeySecret
)
client
,
err
:=
oss
.
New
(
cfg
.
Endpoint
,
cfg
.
AccessKeyId
,
cfg
.
AccessKeySecret
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
NetError
(
err
.
Error
())
}
}
logger
.
Info
(
"bucker name"
+
cfg
.
BucketName
)
logger
.
Info
(
"bucker name"
+
cfg
.
BucketName
)
bucket
,
err
=
client
.
Bucket
(
cfg
.
BucketName
)
bucket
,
err
=
client
.
Bucket
(
cfg
.
BucketName
)
...
@@ -52,7 +52,7 @@ func (*AliyunOSS) UploadFile(reader io.Reader, name string, cfg *AliOssConfig) (
...
@@ -52,7 +52,7 @@ func (*AliyunOSS) UploadFile(reader io.Reader, name string, cfg *AliOssConfig) (
fileTmpPath
:=
cfg
.
BasePath
+
"/"
+
name
fileTmpPath
:=
cfg
.
BasePath
+
"/"
+
name
err
=
bucket
.
PutObject
(
fileTmpPath
,
reader
)
err
=
bucket
.
PutObject
(
fileTmpPath
,
reader
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
xerror
.
New
(
err
.
Error
())
return
""
,
""
,
xerror
.
New
NetError
(
err
.
Error
())
}
}
return
cfg
.
BucketUrl
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
return
cfg
.
BucketUrl
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
}
}
...
@@ -72,7 +72,7 @@ func (x Attachment) NewFromMultipartFileHeaders(files []*multipart.FileHeader) (
...
@@ -72,7 +72,7 @@ func (x Attachment) NewFromMultipartFileHeaders(files []*multipart.FileHeader) (
for
i
:=
range
files
{
for
i
:=
range
files
{
reader
,
err
:=
files
[
i
]
.
Open
()
reader
,
err
:=
files
[
i
]
.
Open
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
NetError
(
err
.
Error
())
}
}
attachment
:=
&
Attachment
{
attachment
:=
&
Attachment
{
File
:
reader
,
File
:
reader
,
...
@@ -105,13 +105,13 @@ func (*AliyunOSS) UploadFiles(files *[]*Attachment, cfg *AliOssConfig) error {
...
@@ -105,13 +105,13 @@ func (*AliyunOSS) UploadFiles(files *[]*Attachment, cfg *AliOssConfig) error {
}
}
bucket
,
err
:=
NewClient
(
cfg
)
bucket
,
err
:=
NewClient
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
NetError
(
err
.
Error
())
}
}
for
i
,
file
:=
range
*
files
{
for
i
,
file
:=
range
*
files
{
relativeUri
:=
cfg
.
BasePath
+
"/"
+
file
.
Name
relativeUri
:=
cfg
.
BasePath
+
"/"
+
file
.
Name
err
=
bucket
.
PutObject
(
relativeUri
,
file
.
File
)
err
=
bucket
.
PutObject
(
relativeUri
,
file
.
File
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
NetError
(
err
.
Error
())
}
}
(
*
files
)[
i
]
.
AbsUrl
=
cfg
.
BucketUrl
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
AbsUrl
=
cfg
.
BucketUrl
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
RelativeUrl
=
relativeUri
(
*
files
)[
i
]
.
RelativeUrl
=
relativeUri
...
...
pkg/sgorm/mysql/mysql.go
浏览文件 @
273e63e8
...
@@ -26,7 +26,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
...
@@ -26,7 +26,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
sqlDB
,
err
:=
sql
.
Open
(
"mysql"
,
dsn
)
sqlDB
,
err
:=
sql
.
Open
(
"mysql"
,
dsn
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
sqlDB
.
SetMaxIdleConns
(
o
.
maxIdleConns
)
// set the maximum number of connections in the idle connection pool
sqlDB
.
SetMaxIdleConns
(
o
.
maxIdleConns
)
// set the maximum number of connections in the idle connection pool
sqlDB
.
SetMaxOpenConns
(
o
.
maxOpenConns
)
// set the maximum number of open database connections
sqlDB
.
SetMaxOpenConns
(
o
.
maxOpenConns
)
// set the maximum number of open database connections
...
@@ -34,7 +34,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
...
@@ -34,7 +34,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
db
,
err
:=
gorm
.
Open
(
mysqlDriver
.
New
(
mysqlDriver
.
Config
{
Conn
:
sqlDB
}),
gormConfig
(
o
))
db
,
err
:=
gorm
.
Open
(
mysqlDriver
.
New
(
mysqlDriver
.
Config
{
Conn
:
sqlDB
}),
gormConfig
(
o
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
db
.
Set
(
"gorm:table_options"
,
"CHARSET=utf8mb4"
)
// automatic appending of table suffixes when creating tables
db
.
Set
(
"gorm:table_options"
,
"CHARSET=utf8mb4"
)
// automatic appending of table suffixes when creating tables
...
@@ -42,17 +42,17 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
...
@@ -42,17 +42,17 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
if
o
.
enableTrace
{
if
o
.
enableTrace
{
err
=
db
.
Use
(
otelgorm
.
NewPlugin
())
err
=
db
.
Use
(
otelgorm
.
NewPlugin
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
Errorf
(
"using gorm opentelemetry, err: %v"
,
err
)
return
nil
,
xerror
.
NewRuntime
Errorf
(
"using gorm opentelemetry, err: %v"
,
err
)
}
}
}
}
if
err
=
sqlDB
.
Ping
();
err
!=
nil
{
if
err
=
sqlDB
.
Ping
();
err
!=
nil
{
return
nil
,
xerror
.
Errorf
(
"ping db failed, err: %v"
,
err
)
return
nil
,
xerror
.
NewRuntime
Errorf
(
"ping db failed, err: %v"
,
err
)
}
}
// register read-write separation plugin
// register read-write separation plugin
if
len
(
o
.
slavesDsn
)
>
0
{
if
len
(
o
.
slavesDsn
)
>
0
{
err
=
db
.
Use
(
rwSeparationPlugin
(
o
))
err
=
db
.
Use
(
rwSeparationPlugin
(
o
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
}
}
...
@@ -60,7 +60,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
...
@@ -60,7 +60,7 @@ func Init(dsn string, opts ...Option) (*gorm.DB, error) {
for
_
,
plugin
:=
range
o
.
plugins
{
for
_
,
plugin
:=
range
o
.
plugins
{
err
=
db
.
Use
(
plugin
)
err
=
db
.
Use
(
plugin
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
}
}
...
...
pkg/sgorm/query/query_condition.go
浏览文件 @
273e63e8
...
@@ -136,10 +136,10 @@ type Column struct {
...
@@ -136,10 +136,10 @@ type Column struct {
func
(
c
*
Column
)
checkValid
()
error
{
func
(
c
*
Column
)
checkValid
()
error
{
if
c
.
Name
==
""
{
if
c
.
Name
==
""
{
return
xerror
.
New
(
"field 'name' cannot be empty"
)
return
xerror
.
New
RuntimeError
(
"field 'name' cannot be empty"
)
}
}
if
c
.
Value
==
nil
{
if
c
.
Value
==
nil
{
return
xerror
.
New
(
"field 'value' cannot be nil"
)
return
xerror
.
New
RuntimeError
(
"field 'value' cannot be nil"
)
}
}
return
nil
return
nil
}
}
...
@@ -157,7 +157,7 @@ func (c *Column) convert() error {
...
@@ -157,7 +157,7 @@ func (c *Column) convert() error {
if
c
.
Exp
==
" IN "
{
if
c
.
Exp
==
" IN "
{
val
,
ok
:=
c
.
Value
.
(
string
)
val
,
ok
:=
c
.
Value
.
(
string
)
if
!
ok
{
if
!
ok
{
return
xerror
.
Newf
(
"invalid value type '%s'"
,
c
.
Value
)
return
xerror
.
New
RuntimeError
f
(
"invalid value type '%s'"
,
c
.
Value
)
}
}
iVal
:=
[]
any
{}
iVal
:=
[]
any
{}
ss
:=
strings
.
Split
(
val
,
","
)
ss
:=
strings
.
Split
(
val
,
","
)
...
@@ -167,7 +167,7 @@ func (c *Column) convert() error {
...
@@ -167,7 +167,7 @@ func (c *Column) convert() error {
c
.
Value
=
iVal
c
.
Value
=
iVal
}
}
}
else
{
}
else
{
return
xerror
.
Newf
(
"unknown exp type '%s'"
,
c
.
Exp
)
return
xerror
.
New
RuntimeError
f
(
"unknown exp type '%s'"
,
c
.
Exp
)
}
}
if
c
.
Logic
==
""
{
if
c
.
Logic
==
""
{
...
@@ -176,7 +176,7 @@ func (c *Column) convert() error {
...
@@ -176,7 +176,7 @@ func (c *Column) convert() error {
if
v
,
ok
:=
logicMap
[
strings
.
ToLower
(
c
.
Logic
)];
ok
{
//nolint
if
v
,
ok
:=
logicMap
[
strings
.
ToLower
(
c
.
Logic
)];
ok
{
//nolint
c
.
Logic
=
v
c
.
Logic
=
v
}
else
{
}
else
{
return
xerror
.
Newf
(
"unknown logic type '%s'"
,
c
.
Logic
)
return
xerror
.
New
RuntimeError
f
(
"unknown logic type '%s'"
,
c
.
Logic
)
}
}
return
nil
return
nil
...
@@ -257,7 +257,7 @@ type Conditions struct {
...
@@ -257,7 +257,7 @@ type Conditions struct {
// CheckValid check valid
// CheckValid check valid
func
(
c
*
Conditions
)
CheckValid
()
error
{
func
(
c
*
Conditions
)
CheckValid
()
error
{
if
len
(
c
.
Columns
)
==
0
{
if
len
(
c
.
Columns
)
==
0
{
return
xerror
.
New
(
"field 'columns' cannot be empty"
)
return
xerror
.
New
RuntimeError
(
"field 'columns' cannot be empty"
)
}
}
for
_
,
column
:=
range
c
.
Columns
{
for
_
,
column
:=
range
c
.
Columns
{
err
:=
column
.
checkValid
()
err
:=
column
.
checkValid
()
...
@@ -266,12 +266,12 @@ func (c *Conditions) CheckValid() error {
...
@@ -266,12 +266,12 @@ func (c *Conditions) CheckValid() error {
}
}
if
column
.
Exp
!=
""
{
if
column
.
Exp
!=
""
{
if
_
,
ok
:=
expMap
[
column
.
Exp
];
!
ok
{
if
_
,
ok
:=
expMap
[
column
.
Exp
];
!
ok
{
return
xerror
.
Newf
(
"unknown exp type '%s'"
,
column
.
Exp
)
return
xerror
.
New
RuntimeError
f
(
"unknown exp type '%s'"
,
column
.
Exp
)
}
}
}
}
if
column
.
Logic
!=
""
{
if
column
.
Logic
!=
""
{
if
_
,
ok
:=
logicMap
[
column
.
Logic
];
!
ok
{
if
_
,
ok
:=
logicMap
[
column
.
Logic
];
!
ok
{
return
xerror
.
Newf
(
"unknown logic type '%s'"
,
column
.
Logic
)
return
xerror
.
New
RuntimeError
f
(
"unknown logic type '%s'"
,
column
.
Logic
)
}
}
}
}
}
}
...
...
pkg/ws/ws.go
浏览文件 @
273e63e8
...
@@ -94,10 +94,10 @@ func (m *WsConnManager) accept(c *gin.Context) error {
...
@@ -94,10 +94,10 @@ func (m *WsConnManager) accept(c *gin.Context) error {
authorization
:=
r
.
URL
.
Query
()
.
Get
(
"auth"
)
authorization
:=
r
.
URL
.
Query
()
.
Get
(
"auth"
)
if
authorization
==
""
{
if
authorization
==
""
{
http
.
Error
(
w
,
"auth required"
,
http
.
StatusUnauthorized
)
http
.
Error
(
w
,
"auth required"
,
http
.
StatusUnauthorized
)
return
xerror
.
New
(
"auth required"
)
return
xerror
.
New
RuntimeError
(
"auth required"
)
}
}
if
len
(
authorization
)
<=
8
{
if
len
(
authorization
)
<=
8
{
return
xerror
.
New
(
"auth required"
)
return
xerror
.
New
RuntimeError
(
"auth required"
)
}
}
token
:=
authorization
[
7
:
]
// remove Bearer prefix
token
:=
authorization
[
7
:
]
// remove Bearer prefix
claims
,
err
:=
jwt
.
ParseToken
(
token
)
claims
,
err
:=
jwt
.
ParseToken
(
token
)
...
@@ -153,7 +153,7 @@ func (m *WsConnManager) Send(ctx context.Context, receiverID xsf.ID, payload *Ws
...
@@ -153,7 +153,7 @@ func (m *WsConnManager) Send(ctx context.Context, receiverID xsf.ID, payload *Ws
h
.
OnConnNotFound
(
receiverID
,
payload
)
h
.
OnConnNotFound
(
receiverID
,
payload
)
}()
}()
}
}
return
xerror
.
Newf
(
"user[id:%d] ws conn not found"
,
receiverID
)
return
xerror
.
New
RuntimeError
f
(
"user[id:%d] ws conn not found"
,
receiverID
)
}
}
for
_
,
h
:=
range
m
.
hooks
{
for
_
,
h
:=
range
m
.
hooks
{
go
func
()
{
go
func
()
{
...
...
pkg/xerrors/xerror/xerror_api.go
浏览文件 @
273e63e8
...
@@ -3,17 +3,18 @@ package xerror
...
@@ -3,17 +3,18 @@ package xerror
import
(
import
(
"fmt"
"fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
)
)
// New 用于创建一个自定义文本错误信息的 error 对象,并包含堆栈信息。
// New 用于创建一个自定义文本错误信息的 error 对象,并包含堆栈信息。
func
New
(
text
string
)
error
{
//
func New(text string) error {
return
&
Err
{
//
return &Err{
stack
:
callers
(),
//
stack: callers(),
text
:
text
,
//
text: text,
code
:
xcode
.
CodeDefault
,
//
code: xcode.CodeDefault,
}
//
}
}
//
}
func
NewNetError
(
text
string
)
error
{
func
NewNetError
(
text
string
)
error
{
e
:=
NetError
{}
e
:=
NetError
{}
...
@@ -23,6 +24,14 @@ func NewNetError(text string) error {
...
@@ -23,6 +24,14 @@ func NewNetError(text string) error {
return
&
e
return
&
e
}
}
func
NewNetErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
NetError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewDBError
(
text
string
)
error
{
func
NewDBError
(
text
string
)
error
{
e
:=
DBError
{}
e
:=
DBError
{}
e
.
stack
=
callers
()
e
.
stack
=
callers
()
...
@@ -31,10 +40,42 @@ func NewDBError(text string) error {
...
@@ -31,10 +40,42 @@ func NewDBError(text string) error {
return
&
e
return
&
e
}
}
func
NewDBErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
DBError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewCacheError
(
text
string
)
error
{
e
:=
CacheError
{}
e
.
stack
=
callers
()
e
.
text
=
text
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewCacheErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
CacheError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewParamError
(
text
string
)
error
{
func
NewParamError
(
text
string
)
error
{
e
:=
ParamError
{}
e
:=
ParamError
{}
e
.
stack
=
callers
()
e
.
stack
=
callers
()
e
.
text
=
text
e
.
text
=
text
e
.
code
=
errcode
.
InvalidParams
.
Code
()
return
&
e
}
func
NewParamErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
ParamError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
e
.
code
=
xcode
.
CodeDefault
return
&
e
return
&
e
}
}
...
@@ -47,13 +88,45 @@ func NewBizError(text string) error {
...
@@ -47,13 +88,45 @@ func NewBizError(text string) error {
return
&
e
return
&
e
}
}
func
NewBizErrorC
(
code
int
,
text
string
)
error
{
e
:=
BizError
{}
e
.
stack
=
callers
()
e
.
text
=
text
e
.
code
=
code
return
&
e
}
func
NewBizErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
BizError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewRuntimeError
(
text
string
)
error
{
e
:=
RuntimeError
{}
e
.
stack
=
callers
()
e
.
text
=
text
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
func
NewRuntimeErrorf
(
format
string
,
args
...
any
)
error
{
e
:=
RuntimeError
{}
e
.
stack
=
callers
()
e
.
text
=
fmt
.
Sprintf
(
format
,
args
...
)
e
.
code
=
xcode
.
CodeDefault
return
&
e
}
// NewC add code
// NewC add code
func
NewC
(
code
int
,
text
string
)
error
{
func
NewC
(
code
int
,
text
string
)
error
{
return
&
Err
{
e
:=
BizError
{}
stack
:
callers
(),
e
.
stack
=
callers
()
text
:
text
,
e
.
text
=
text
code
:
code
,
e
.
code
=
code
}
return
&
e
}
}
func
Join
(
errs
...
error
)
error
{
func
Join
(
errs
...
error
)
error
{
...
...
pkg/xerrors/xerror/xerror_error.go
浏览文件 @
273e63e8
...
@@ -24,6 +24,10 @@ type DBError struct {
...
@@ -24,6 +24,10 @@ type DBError struct {
Err
Err
}
}
type
CacheError
struct
{
Err
}
type
ParamError
struct
{
type
ParamError
struct
{
Err
Err
}
}
...
@@ -32,6 +36,10 @@ type BizError struct {
...
@@ -32,6 +36,10 @@ type BizError struct {
Err
Err
}
}
type
RuntimeError
struct
{
Err
}
const
(
const
(
// stackFilterKeyLocal 过滤当前错误模块路径的键。
// stackFilterKeyLocal 过滤当前错误模块路径的键。
stackFilterKeyLocal
=
"/xerrors/xerror"
stackFilterKeyLocal
=
"/xerrors/xerror"
...
...
pkg/xerrors/xerror/xerror_z_bench_test.go
浏览文件 @
273e63e8
...
@@ -15,7 +15,7 @@ var (
...
@@ -15,7 +15,7 @@ var (
func
Benchmark_New
(
b
*
testing
.
B
)
{
func
Benchmark_New
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
xerror
.
New
(
"test"
)
xerror
.
New
RuntimeError
(
"test"
)
}
}
}
}
...
...
pkg/xerrors/xerror/xerror_z_example_test.go
浏览文件 @
273e63e8
...
@@ -53,7 +53,7 @@ func ExampleWrapCodef() {
...
@@ -53,7 +53,7 @@ func ExampleWrapCodef() {
func
ExampleEqual
()
{
func
ExampleEqual
()
{
err1
:=
errors
.
New
(
"permission denied"
)
err1
:=
errors
.
New
(
"permission denied"
)
err2
:=
xerror
.
New
(
"permission denied"
)
err2
:=
xerror
.
New
RuntimeError
(
"permission denied"
)
err3
:=
xerror
.
NewCode
(
xcode
.
CodeNotAuthorized
,
"permission denied"
)
err3
:=
xerror
.
NewCode
(
xcode
.
CodeNotAuthorized
,
"permission denied"
)
fmt
.
Println
(
xerror
.
Equal
(
err1
,
err2
))
fmt
.
Println
(
xerror
.
Equal
(
err1
,
err2
))
fmt
.
Println
(
xerror
.
Equal
(
err2
,
err3
))
fmt
.
Println
(
xerror
.
Equal
(
err2
,
err3
))
...
...
pkg/xerrors/xerror/xerror_z_unit_test.go
浏览文件 @
273e63e8
...
@@ -21,12 +21,12 @@ func nilError() error {
...
@@ -21,12 +21,12 @@ func nilError() error {
}
}
func
Test_Nil
(
t
*
testing
.
T
)
{
func
Test_Nil
(
t
*
testing
.
T
)
{
assert
.
NotNil
(
t
,
xerror
.
New
(
""
))
assert
.
NotNil
(
t
,
xerror
.
New
RuntimeError
(
""
))
assert
.
Nil
(
t
,
xerror
.
Wrap
(
nilError
(),
"test"
))
assert
.
Nil
(
t
,
xerror
.
Wrap
(
nilError
(),
"test"
))
}
}
func
Test_New
(
t
*
testing
.
T
)
{
func
Test_New
(
t
*
testing
.
T
)
{
err1
:=
xerror
.
New
(
"1"
)
err1
:=
xerror
.
New
RuntimeError
(
"1"
)
assert
.
NotNil
(
t
,
err1
)
assert
.
NotNil
(
t
,
err1
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"1"
)
...
@@ -46,7 +46,7 @@ func Test_Wrap(t *testing.T) {
...
@@ -46,7 +46,7 @@ func Test_Wrap(t *testing.T) {
assert
.
NotNil
(
t
,
err1
)
assert
.
NotNil
(
t
,
err1
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
err2
=
xerror
.
Wrap
(
err2
,
""
)
err2
=
xerror
.
Wrap
(
err2
,
""
)
assert
.
NotNil
(
t
,
err2
)
assert
.
NotNil
(
t
,
err2
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
...
@@ -59,7 +59,7 @@ func Test_Wrapf(t *testing.T) {
...
@@ -59,7 +59,7 @@ func Test_Wrapf(t *testing.T) {
assert
.
NotNil
(
t
,
err1
)
assert
.
NotNil
(
t
,
err1
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
err2
=
xerror
.
Wrapf
(
err2
,
""
)
err2
=
xerror
.
Wrapf
(
err2
,
""
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
...
@@ -72,7 +72,7 @@ func Test_WrapSkip(t *testing.T) {
...
@@ -72,7 +72,7 @@ func Test_WrapSkip(t *testing.T) {
assert
.
NotNil
(
t
,
err1
,
nil
)
assert
.
NotNil
(
t
,
err1
,
nil
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
err2
=
xerror
.
WrapSkip
(
1
,
err2
,
""
)
err2
=
xerror
.
WrapSkip
(
1
,
err2
,
""
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
...
@@ -85,7 +85,7 @@ func Test_WrapSkipf(t *testing.T) {
...
@@ -85,7 +85,7 @@ func Test_WrapSkipf(t *testing.T) {
assert
.
NotNil
(
t
,
err1
,
nil
)
assert
.
NotNil
(
t
,
err1
,
nil
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
assert
.
Equal
(
t
,
err1
.
Error
(),
"3: 2: 1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
err2
=
xerror
.
WrapSkipf
(
1
,
err2
,
""
)
err2
=
xerror
.
WrapSkipf
(
1
,
err2
,
""
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
err2
.
Error
(),
"1"
)
...
@@ -100,10 +100,10 @@ func Test_Cause(t *testing.T) {
...
@@ -100,10 +100,10 @@ func Test_Cause(t *testing.T) {
err1
=
xerror
.
Wrap
(
err1
,
"3"
)
err1
=
xerror
.
Wrap
(
err1
,
"3"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err1
)
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err1
)
.
Error
(),
"1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err2
)
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err2
)
.
Error
(),
"1"
)
err3
:=
xerror
.
New
(
"1"
)
err3
:=
xerror
.
New
RuntimeError
(
"1"
)
err3
=
xerror
.
Wrap
(
err3
,
"2"
)
err3
=
xerror
.
Wrap
(
err3
,
"2"
)
err3
=
xerror
.
Wrap
(
err3
,
"3"
)
err3
=
xerror
.
Wrap
(
err3
,
"3"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err3
)
.
Error
(),
"1"
)
assert
.
Equal
(
t
,
xerror
.
Cause
(
err3
)
.
Error
(),
"1"
)
...
@@ -117,7 +117,7 @@ func Test_Format(t *testing.T) {
...
@@ -117,7 +117,7 @@ func Test_Format(t *testing.T) {
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
"%s"
,
err1
),
"3: 2: 1"
)
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
"%s"
,
err1
),
"3: 2: 1"
)
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
"%v"
,
err1
),
"3: 2: 1"
)
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
"%v"
,
err1
),
"3: 2: 1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
err2
=
xerror
.
Wrap
(
err2
,
"2"
)
err2
=
xerror
.
Wrap
(
err2
,
"2"
)
err2
=
xerror
.
Wrap
(
err2
,
"3"
)
err2
=
xerror
.
Wrap
(
err2
,
"3"
)
assert
.
NotNil
(
t
,
err2
,
nil
)
assert
.
NotNil
(
t
,
err2
,
nil
)
...
@@ -135,11 +135,11 @@ func Test_Stack(t *testing.T) {
...
@@ -135,11 +135,11 @@ func Test_Stack(t *testing.T) {
assert
.
NotNil
(
t
,
err1
,
nil
)
assert
.
NotNil
(
t
,
err1
,
nil
)
// fmt.Printf("%+v", err1)
// fmt.Printf("%+v", err1)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
assert
.
NotNil
(
t
,
fmt
.
Sprintf
(
"%+v"
,
err2
),
"1"
)
assert
.
NotNil
(
t
,
fmt
.
Sprintf
(
"%+v"
,
err2
),
"1"
)
// fmt.Printf("%+v", err2)
// fmt.Printf("%+v", err2)
err3
:=
xerror
.
New
(
"1"
)
err3
:=
xerror
.
New
RuntimeError
(
"1"
)
err3
=
xerror
.
Wrap
(
err3
,
"2"
)
err3
=
xerror
.
Wrap
(
err3
,
"2"
)
err3
=
xerror
.
Wrap
(
err3
,
"3"
)
err3
=
xerror
.
Wrap
(
err3
,
"3"
)
assert
.
NotNil
(
t
,
err3
,
nil
)
assert
.
NotNil
(
t
,
err3
,
nil
)
...
@@ -217,7 +217,7 @@ func Test_Code(t *testing.T) {
...
@@ -217,7 +217,7 @@ func Test_Code(t *testing.T) {
}
}
func
Test_SetCode
(
t
*
testing
.
T
)
{
func
Test_SetCode
(
t
*
testing
.
T
)
{
err
:=
xerror
.
New
(
"123"
)
err
:=
xerror
.
New
RuntimeError
(
"123"
)
assert
.
Equal
(
t
,
xerror
.
Code
(
err
),
-
1
)
assert
.
Equal
(
t
,
xerror
.
Code
(
err
),
-
1
)
assert
.
Equal
(
t
,
err
.
Error
(),
"123"
)
assert
.
Equal
(
t
,
err
.
Error
(),
"123"
)
...
@@ -227,7 +227,7 @@ func Test_SetCode(t *testing.T) {
...
@@ -227,7 +227,7 @@ func Test_SetCode(t *testing.T) {
}
}
func
Test_Json
(
t
*
testing
.
T
)
{
func
Test_Json
(
t
*
testing
.
T
)
{
err
:=
xerror
.
Wrap
(
xerror
.
New
(
"1"
),
"2"
)
err
:=
xerror
.
Wrap
(
xerror
.
New
RuntimeError
(
"1"
),
"2"
)
b
,
e
:=
json
.
Marshal
(
err
)
b
,
e
:=
json
.
Marshal
(
err
)
assert
.
Equal
(
t
,
e
,
nil
)
assert
.
Equal
(
t
,
e
,
nil
)
assert
.
Equal
(
t
,
string
(
b
),
`"2: 1"`
)
assert
.
Equal
(
t
,
string
(
b
),
`"2: 1"`
)
...
@@ -235,7 +235,7 @@ func Test_Json(t *testing.T) {
...
@@ -235,7 +235,7 @@ func Test_Json(t *testing.T) {
func
Test_HasStack
(
t
*
testing
.
T
)
{
func
Test_HasStack
(
t
*
testing
.
T
)
{
err1
:=
errors
.
New
(
"1"
)
err1
:=
errors
.
New
(
"1"
)
err2
:=
xerror
.
New
(
"1"
)
err2
:=
xerror
.
New
RuntimeError
(
"1"
)
assert
.
Equal
(
t
,
xerror
.
HasStack
(
err1
),
false
)
assert
.
Equal
(
t
,
xerror
.
HasStack
(
err1
),
false
)
assert
.
Equal
(
t
,
xerror
.
HasStack
(
err2
),
true
)
assert
.
Equal
(
t
,
xerror
.
HasStack
(
err2
),
true
)
}
}
...
@@ -243,8 +243,8 @@ func Test_HasStack(t *testing.T) {
...
@@ -243,8 +243,8 @@ func Test_HasStack(t *testing.T) {
func
Test_Equal
(
t
*
testing
.
T
)
{
func
Test_Equal
(
t
*
testing
.
T
)
{
err1
:=
errors
.
New
(
"1"
)
err1
:=
errors
.
New
(
"1"
)
err2
:=
errors
.
New
(
"1"
)
err2
:=
errors
.
New
(
"1"
)
err3
:=
xerror
.
New
(
"1"
)
err3
:=
xerror
.
New
RuntimeError
(
"1"
)
err4
:=
xerror
.
New
(
"4"
)
err4
:=
xerror
.
New
RuntimeError
(
"4"
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err1
,
err2
),
false
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err1
,
err2
),
false
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err1
,
err3
),
true
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err1
,
err3
),
true
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err2
,
err3
),
true
)
assert
.
Equal
(
t
,
xerror
.
Equal
(
err2
,
err3
),
true
)
...
@@ -260,7 +260,7 @@ func Test_Is(t *testing.T) {
...
@@ -260,7 +260,7 @@ func Test_Is(t *testing.T) {
assert
.
Equal
(
t
,
xerror
.
Is
(
err2
,
err1
),
true
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err2
,
err1
),
true
)
err3
:=
xerror
.
Wrap
(
gorm
.
ErrRecordNotFound
,
"3"
)
err3
:=
xerror
.
Wrap
(
gorm
.
ErrRecordNotFound
,
"3"
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err3
,
gorm
.
ErrRecordNotFound
),
true
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err3
,
gorm
.
ErrRecordNotFound
),
true
)
err4
:=
xerror
.
New
(
gorm
.
ErrRecordNotFound
.
Error
())
err4
:=
xerror
.
New
RuntimeError
(
gorm
.
ErrRecordNotFound
.
Error
())
assert
.
Equal
(
t
,
xerror
.
Is
(
err4
,
gorm
.
ErrRecordNotFound
),
true
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err4
,
gorm
.
ErrRecordNotFound
),
true
)
err5
:=
xerror
.
WrapCode
(
1
,
gorm
.
ErrRecordNotFound
,
"exes"
)
err5
:=
xerror
.
WrapCode
(
1
,
gorm
.
ErrRecordNotFound
,
"exes"
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err5
,
gorm
.
ErrRecordNotFound
),
true
)
assert
.
Equal
(
t
,
xerror
.
Is
(
err5
,
gorm
.
ErrRecordNotFound
),
true
)
...
...
xcommon/ocache/ocache.go
浏览文件 @
273e63e8
...
@@ -69,7 +69,7 @@ func (x *OCache[T]) Set(ctx context.Context, id xsf.ID, data *T, duration time.D
...
@@ -69,7 +69,7 @@ func (x *OCache[T]) Set(ctx context.Context, id xsf.ID, data *T, duration time.D
}
}
cacheKey
:=
getCacheKey
(
x
.
KeyPrefix
,
id
.
Int64
())
cacheKey
:=
getCacheKey
(
x
.
KeyPrefix
,
id
.
Int64
())
if
err
:=
x
.
Cache
.
Set
(
ctx
,
cacheKey
,
data
,
duration
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
Set
(
ctx
,
cacheKey
,
data
,
duration
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
@@ -81,7 +81,7 @@ func (x *OCache[T]) Get(ctx context.Context, id xsf.ID) (*T, error) {
...
@@ -81,7 +81,7 @@ func (x *OCache[T]) Get(ctx context.Context, id xsf.ID) (*T, error) {
var
data
*
T
var
data
*
T
cacheKey
:=
getCacheKey
(
x
.
KeyPrefix
,
id
.
Int64
())
cacheKey
:=
getCacheKey
(
x
.
KeyPrefix
,
id
.
Int64
())
if
err
:=
x
.
Cache
.
Get
(
ctx
,
cacheKey
,
&
data
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
Get
(
ctx
,
cacheKey
,
&
data
);
err
!=
nil
{
return
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
data
,
nil
return
data
,
nil
}
}
...
@@ -97,7 +97,7 @@ func (x *OCache[T]) MultiSet(ctx context.Context, data []*T, duration time.Durat
...
@@ -97,7 +97,7 @@ func (x *OCache[T]) MultiSet(ctx context.Context, data []*T, duration time.Durat
}
}
if
err
:=
x
.
Cache
.
MultiSet
(
ctx
,
valMap
,
duration
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
MultiSet
(
ctx
,
valMap
,
duration
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
nil
return
nil
...
@@ -117,7 +117,7 @@ func (x *OCache[T]) MultiGet(ctx context.Context, ids []xsf.ID) (map[xsf.ID]int,
...
@@ -117,7 +117,7 @@ func (x *OCache[T]) MultiGet(ctx context.Context, ids []xsf.ID) (map[xsf.ID]int,
}
}
items
,
err
:=
x
.
Cache
.
MGet
(
ctx
,
keys
)
items
,
err
:=
x
.
Cache
.
MGet
(
ctx
,
keys
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
xerror
.
New
(
err
.
Error
())
return
nil
,
nil
,
xerror
.
New
CacheError
(
err
.
Error
())
}
}
retMap
:=
make
(
map
[
xsf
.
ID
]
*
T
)
retMap
:=
make
(
map
[
xsf
.
ID
]
*
T
)
hasMap
:=
make
(
map
[
xsf
.
ID
]
int
)
hasMap
:=
make
(
map
[
xsf
.
ID
]
int
)
...
@@ -141,7 +141,7 @@ func (x *OCache[T]) MultiGet(ctx context.Context, ids []xsf.ID) (map[xsf.ID]int,
...
@@ -141,7 +141,7 @@ func (x *OCache[T]) MultiGet(ctx context.Context, ids []xsf.ID) (map[xsf.ID]int,
func
(
x
*
OCache
[
T
])
Del
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
func
(
x
*
OCache
[
T
])
Del
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
cacheKey
:=
x
.
KeyPrefix
+
utils
.
Int64ToStr
(
id
.
Int64
())
cacheKey
:=
x
.
KeyPrefix
+
utils
.
Int64ToStr
(
id
.
Int64
())
if
err
:=
x
.
Cache
.
Del
(
ctx
,
cacheKey
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
Del
(
ctx
,
cacheKey
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
@@ -156,7 +156,7 @@ func (x *OCache[T]) Dels(ctx context.Context, ids []xsf.ID) error {
...
@@ -156,7 +156,7 @@ func (x *OCache[T]) Dels(ctx context.Context, ids []xsf.ID) error {
keys
=
append
(
keys
,
cacheKey
)
keys
=
append
(
keys
,
cacheKey
)
}
}
if
err
:=
x
.
Cache
.
Del
(
ctx
,
keys
...
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
Del
(
ctx
,
keys
...
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
@@ -164,7 +164,7 @@ func (x *OCache[T]) Dels(ctx context.Context, ids []xsf.ID) error {
...
@@ -164,7 +164,7 @@ func (x *OCache[T]) Dels(ctx context.Context, ids []xsf.ID) error {
func
(
x
*
OCache
[
T
])
SetPlaceholder
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
func
(
x
*
OCache
[
T
])
SetPlaceholder
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
cacheKey
:=
x
.
KeyPrefix
+
utils
.
Int64ToStr
(
id
.
Int64
())
cacheKey
:=
x
.
KeyPrefix
+
utils
.
Int64ToStr
(
id
.
Int64
())
if
err
:=
x
.
Cache
.
SetCacheWithNotFound
(
ctx
,
cacheKey
);
err
!=
nil
{
if
err
:=
x
.
Cache
.
SetCacheWithNotFound
(
ctx
,
cacheKey
);
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
CacheError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
...
xcommon/odao/odao.go
浏览文件 @
273e63e8
...
@@ -356,7 +356,7 @@ func (x *ODao[T]) JList(ctx context.Context, where IListParams, result any, resu
...
@@ -356,7 +356,7 @@ func (x *ODao[T]) JList(ctx context.Context, where IListParams, result any, resu
func
(
x
*
ODao
[
T
])
GetPageByColumns
(
ctx
context
.
Context
,
params
*
query
.
Params
)
(
rs
[]
*
T
,
total
int64
,
err
error
)
{
func
(
x
*
ODao
[
T
])
GetPageByColumns
(
ctx
context
.
Context
,
params
*
query
.
Params
)
(
rs
[]
*
T
,
total
int64
,
err
error
)
{
queryStr
,
args
,
err
:=
params
.
ConvertToGormConditions
()
queryStr
,
args
,
err
:=
params
.
ConvertToGormConditions
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
xerror
.
New
(
"query params error: "
+
err
.
Error
())
return
nil
,
0
,
xerror
.
New
DBError
(
"query params error: "
+
err
.
Error
())
}
}
if
params
.
Sort
!=
OrderIgnoreCount
{
if
params
.
Sort
!=
OrderIgnoreCount
{
var
tb
T
var
tb
T
...
...
xcron/dao/cron_job.go
浏览文件 @
273e63e8
...
@@ -93,7 +93,7 @@ func (x *cronJobDao) GetNotRunning(ctx context.Context, id xsf.ID) (*models.Cron
...
@@ -93,7 +93,7 @@ func (x *cronJobDao) GetNotRunning(ctx context.Context, id xsf.ID) (*models.Cron
Where
(
"state = ?"
,
enums
.
CronJob_State_NOT_RUNNING
)
.
Where
(
"id = ?"
,
id
)
.
Where
(
"state = ?"
,
enums
.
CronJob_State_NOT_RUNNING
)
.
Where
(
"id = ?"
,
id
)
.
Update
(
"state"
,
enums
.
CronJob_State_RUNNING
)
Update
(
"state"
,
enums
.
CronJob_State_RUNNING
)
if
result
.
Error
!=
nil
{
if
result
.
Error
!=
nil
{
return
nil
,
xerror
.
New
(
result
.
Error
.
Error
())
return
nil
,
xerror
.
New
DBError
(
result
.
Error
.
Error
())
}
}
if
result
.
RowsAffected
==
0
{
if
result
.
RowsAffected
==
0
{
return
nil
,
nil
return
nil
,
nil
...
...
xcron/service/cron_job.go
浏览文件 @
273e63e8
...
@@ -62,7 +62,7 @@ func (x *cronJobService) DeleteByID(ctx context.Context, id xsf.ID) error {
...
@@ -62,7 +62,7 @@ func (x *cronJobService) DeleteByID(ctx context.Context, id xsf.ID) error {
return
err
return
err
}
}
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
xerror
.
New
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
id
))
return
xerror
.
New
BizError
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
id
))
}
}
return
dao
.
CronJobDao
.
DeleteByID
(
ctx
,
id
)
return
dao
.
CronJobDao
.
DeleteByID
(
ctx
,
id
)
}
}
...
@@ -107,7 +107,7 @@ func (x *cronJobService) UpdateByID(ctx context.Context, req *types.CronJobUpdat
...
@@ -107,7 +107,7 @@ func (x *cronJobService) UpdateByID(ctx context.Context, req *types.CronJobUpdat
return
err
return
err
}
}
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
xerror
.
New
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
req
.
ID
))
return
xerror
.
New
BizError
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
req
.
ID
))
}
}
cronJobUpd
:=
&
models
.
CronJob
{}
cronJobUpd
:=
&
models
.
CronJob
{}
_
=
copier
.
Copy
(
cronJobUpd
,
req
)
_
=
copier
.
Copy
(
cronJobUpd
,
req
)
...
...
xutils/goutils/go.go
浏览文件 @
273e63e8
...
@@ -45,7 +45,7 @@ func Do(ctx context.Context, fns ...FnCtx) error {
...
@@ -45,7 +45,7 @@ func Do(ctx context.Context, fns ...FnCtx) error {
})
})
}
}
if
err
:=
eg
.
Wait
();
err
!=
nil
{
if
err
:=
eg
.
Wait
();
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
@@ -63,7 +63,7 @@ func DoWithTimeout(timeout time.Duration, fns ...FnCtx) error {
...
@@ -63,7 +63,7 @@ func DoWithTimeout(timeout time.Duration, fns ...FnCtx) error {
})
})
}
}
if
err
:=
eg
.
Wait
();
err
!=
nil
{
if
err
:=
eg
.
Wait
();
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
xutils/jsonutils/json.go
浏览文件 @
273e63e8
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
func
Unmarshal
(
data
[]
byte
,
v
any
)
error
{
func
Unmarshal
(
data
[]
byte
,
v
any
)
error
{
err
:=
json
.
Unmarshal
(
data
,
v
)
err
:=
json
.
Unmarshal
(
data
,
v
)
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
return
nil
return
nil
}
}
...
...
xutils/redsyncutils/red_sync_utils.go
浏览文件 @
273e63e8
...
@@ -31,13 +31,13 @@ func initialize(redisCli *redis.Client) {
...
@@ -31,13 +31,13 @@ func initialize(redisCli *redis.Client) {
func
Sync
(
ctx
context
.
Context
,
key
string
,
fn
func
(),
options
...
redsync
.
Option
)
error
{
func
Sync
(
ctx
context
.
Context
,
key
string
,
fn
func
(),
options
...
redsync
.
Option
)
error
{
if
key
==
""
{
if
key
==
""
{
return
xerror
.
New
(
"[redSync]key is empty, please check"
)
return
xerror
.
New
RuntimeError
(
"[redSync]key is empty, please check"
)
}
}
if
fn
==
nil
{
if
fn
==
nil
{
return
xerror
.
New
(
"[redSync]fn is nil, please check"
)
return
xerror
.
New
RuntimeError
(
"[redSync]fn is nil, please check"
)
}
}
if
redSync
==
nil
{
if
redSync
==
nil
{
return
xerror
.
New
(
"[redSync]redSync is nil, please init first"
)
return
xerror
.
New
RuntimeError
(
"[redSync]redSync is nil, please init first"
)
}
}
mutex
:=
redSync
.
NewMutex
(
key
,
options
...
)
mutex
:=
redSync
.
NewMutex
(
key
,
options
...
)
if
err
:=
mutex
.
LockContext
(
ctx
);
err
!=
nil
{
if
err
:=
mutex
.
LockContext
(
ctx
);
err
!=
nil
{
...
...
xutils/sliceutils/xslice.go
浏览文件 @
273e63e8
...
@@ -245,14 +245,14 @@ func CompareSlice[ID xtype.Key, T IIDTable[ID], BizSlice ~[]*T](ids []ID, bizSli
...
@@ -245,14 +245,14 @@ func CompareSlice[ID xtype.Key, T IIDTable[ID], BizSlice ~[]*T](ids []ID, bizSli
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
return
xerror
.
NewC
(
v
.
Code
(),
v
.
Msg
())
return
xerror
.
NewC
(
v
.
Code
(),
v
.
Msg
())
}
}
return
xerror
.
New
(
errCode
.
Error
())
return
xerror
.
New
BizError
(
errCode
.
Error
())
}
}
deltaIDs
:=
SetDifference
(
ids
,
GetIDs
[
ID
](
bizSlice
))
deltaIDs
:=
SetDifference
(
ids
,
GetIDs
[
ID
](
bizSlice
))
if
len
(
deltaIDs
)
>
0
{
if
len
(
deltaIDs
)
>
0
{
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
return
xerror
.
NewC
(
v
.
Code
(),
fmt
.
Sprintf
(
"%s[ids:%s]"
,
v
.
Msg
(),
Join
(
deltaIDs
,
","
)))
return
xerror
.
NewC
(
v
.
Code
(),
fmt
.
Sprintf
(
"%s[ids:%s]"
,
v
.
Msg
(),
Join
(
deltaIDs
,
","
)))
}
}
return
xerror
.
New
(
errCode
.
Error
())
return
xerror
.
New
BizError
(
errCode
.
Error
())
}
}
}
}
return
nil
return
nil
...
...
xutils/wg/wg.go
浏览文件 @
273e63e8
...
@@ -11,10 +11,10 @@ import (
...
@@ -11,10 +11,10 @@ import (
func
Go
(
ctx
context
.
Context
,
n
int
,
fn
func
()
error
)
error
{
func
Go
(
ctx
context
.
Context
,
n
int
,
fn
func
()
error
)
error
{
if
n
<=
0
{
if
n
<=
0
{
return
xerror
.
New
(
"n cannot be less or equal then 0"
)
return
xerror
.
New
RuntimeError
(
"n cannot be less or equal then 0"
)
}
}
if
fn
==
nil
{
if
fn
==
nil
{
return
xerror
.
New
(
"fn cannot be nil"
)
return
xerror
.
New
RuntimeError
(
"fn cannot be nil"
)
}
}
wg
:=
&
sync
.
WaitGroup
{}
wg
:=
&
sync
.
WaitGroup
{}
wg
.
Add
(
n
)
wg
.
Add
(
n
)
...
...
xutils/xsf/xsf.go
浏览文件 @
273e63e8
...
@@ -150,7 +150,7 @@ func ParseInt64(val int64) ID {
...
@@ -150,7 +150,7 @@ func ParseInt64(val int64) ID {
func
ParseString
(
val
string
)
(
ID
,
error
)
{
func
ParseString
(
val
string
)
(
ID
,
error
)
{
v
,
err
:=
snowflake
.
ParseString
(
val
)
v
,
err
:=
snowflake
.
ParseString
(
val
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
xerror
.
New
(
err
.
Error
())
return
0
,
xerror
.
New
RuntimeError
(
err
.
Error
())
}
}
return
ID
(
v
),
nil
return
ID
(
v
),
nil
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论