Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
ea1c2441
提交
ea1c2441
authored
9月 18, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
e06545fc
全部展开
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
26 行增加
和
157 行删除
+26
-157
convert_utils.go
utils/convert_utils/convert_utils.go
+1
-1
eg.go
utils/eg_utils/eg.go
+7
-9
httpUtils.go
utils/httpUtils/httpUtils.go
+0
-81
jsonUtils.go
utils/json_utils/jsonUtils.go
+1
-1
map_utils.go
utils/map_utils/map_utils.go
+1
-1
webLogUtils.go
utils/webLogUtils/webLogUtils.go
+12
-16
weblog.sql
utils/webLogUtils/weblog.sql
+2
-2
datetime.go
utils/xtime/datetime.go
+0
-2
xtime.tmp.go
utils/xtime/xtime.tmp.go
+0
-0
xtime.tmp_test.go
utils/xtime/xtime.tmp_test.go
+0
-42
controller.go
xcommon/controller.go
+2
-2
没有找到文件。
utils/convert
Utils/convertU
tils.go
→
utils/convert
_utils/convert_u
tils.go
浏览文件 @
ea1c2441
package
convert
U
tils
package
convert
_u
tils
import
"strconv"
import
"strconv"
...
...
utils/
xeg/x
eg.go
→
utils/
eg_utils/
eg.go
浏览文件 @
ea1c2441
package
xeg
package
eg_utils
import
(
import
(
"context"
"context"
...
@@ -16,14 +16,13 @@ func Do(ctx context.Context, fns ...FnCtx) error {
...
@@ -16,14 +16,13 @@ func Do(ctx context.Context, fns ...FnCtx) error {
}
}
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
defer
cancel
()
g
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
e
g
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
for
_
,
fn
:=
range
fns
{
for
_
,
fn
:=
range
fns
{
g
.
Go
(
func
()
error
{
e
g
.
Go
(
func
()
error
{
return
fn
(
ctx
)
return
fn
(
ctx
)
})
})
}
}
err
:=
g
.
Wait
()
if
err
:=
eg
.
Wait
();
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
(
err
.
Error
())
}
}
return
nil
return
nil
...
@@ -35,14 +34,13 @@ func DoWithTimeout(timeout time.Duration, fns ...FnCtx) error {
...
@@ -35,14 +34,13 @@ func DoWithTimeout(timeout time.Duration, fns ...FnCtx) error {
}
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
defer
cancel
()
g
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
e
g
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
for
_
,
fn
:=
range
fns
{
for
_
,
fn
:=
range
fns
{
g
.
Go
(
func
()
error
{
e
g
.
Go
(
func
()
error
{
return
fn
(
ctx
)
return
fn
(
ctx
)
})
})
}
}
err
:=
g
.
Wait
()
if
err
:=
eg
.
Wait
();
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
return
xerror
.
New
(
err
.
Error
())
}
}
return
nil
return
nil
...
...
utils/httpUtils/httpUtils.go
deleted
100644 → 0
浏览文件 @
e06545fc
package
httpUtils
import
(
"net/http"
"time"
)
type
Request
struct
{
method
string
url
string
params
map
[
string
]
interface
{}
headers
map
[
string
]
string
body
any
bodyJSON
any
timeout
time
.
Duration
retry
uint
request
*
http
.
Request
response
*
http
.
Response
err
error
}
func
New
()
*
Request
{
return
&
Request
{
request
:
&
http
.
Request
{},
headers
:
map
[
string
]
string
{},
params
:
map
[
string
]
interface
{}{},
}
}
func
(
req
*
Request
)
SetURL
(
path
string
)
*
Request
{
req
.
url
=
path
return
req
}
func
(
req
*
Request
)
SetParams
(
params
map
[
string
]
any
)
*
Request
{
if
req
.
params
==
nil
{
req
.
params
=
params
}
else
{
for
k
,
v
:=
range
params
{
req
.
params
[
k
]
=
v
}
}
return
req
}
func
(
req
*
Request
)
SetParam
(
k
string
,
v
interface
{})
*
Request
{
if
req
.
params
==
nil
{
req
.
params
=
make
(
map
[
string
]
interface
{})
}
req
.
params
[
k
]
=
v
return
req
}
func
(
req
*
Request
)
SetBody
(
body
interface
{})
*
Request
{
switch
v
:=
body
.
(
type
)
{
case
string
:
req
.
body
=
v
case
[]
byte
:
req
.
body
=
string
(
v
)
default
:
req
.
bodyJSON
=
body
}
return
req
}
func
(
req
*
Request
)
SetHeader
(
k
,
v
string
)
*
Request
{
if
req
.
headers
==
nil
{
req
.
headers
=
make
(
map
[
string
]
string
)
}
req
.
headers
[
k
]
=
v
return
req
}
func
(
req
*
Request
)
SetTimeout
(
t
time
.
Duration
)
*
Request
{
req
.
timeout
=
t
return
req
}
func
(
req
*
Request
)
SetRetry
(
retry
uint
)
*
Request
{
req
.
retry
=
retry
return
req
}
func
(
req
*
Request
)
SetContentType
(
a
string
)
*
Request
{
req
.
SetHeader
(
"Content-Type"
,
a
)
return
req
}
utils/json
U
tils/jsonUtils.go
→
utils/json
_u
tils/jsonUtils.go
浏览文件 @
ea1c2441
package
json
U
tils
package
json
_u
tils
import
(
import
(
"bytes"
"bytes"
...
...
utils/map
Utils/mapU
tils.go
→
utils/map
_utils/map_u
tils.go
浏览文件 @
ea1c2441
package
map
U
tils
package
map
_u
tils
import
(
import
(
"encoding/json"
"encoding/json"
...
...
utils/webLogUtils/webLogUtils.go
浏览文件 @
ea1c2441
...
@@ -16,7 +16,7 @@ import (
...
@@ -16,7 +16,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/logger"
merge
"gitlab.wanzhuangkj.com/tush/xpkg/merger"
merge
"gitlab.wanzhuangkj.com/tush/xpkg/merger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/json
U
tils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/json
_u
tils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
...
@@ -101,7 +101,7 @@ func Init(schema string, isProd bool) {
...
@@ -101,7 +101,7 @@ func Init(schema string, isProd bool) {
}
}
insertFn
:=
func
()
error
{
insertFn
:=
func
()
error
{
if
err
:=
WebLogDao
.
CreateSliceSilent
(
ctx
,
ors
);
err
!=
nil
{
if
err
:=
WebLogDao
.
CreateSliceSilent
(
ctx
,
ors
);
err
!=
nil
{
logger
.
Error
(
"[webLog] insert fail detail"
,
ctxUtils
.
CtxTraceIDField
(
ctx
))
logger
.
Error
(
"[webLog] insert fail detail"
,
logger
.
Err
(
err
),
ctxUtils
.
CtxTraceIDField
(
ctx
))
return
err
return
err
}
}
return
nil
return
nil
...
@@ -123,21 +123,21 @@ func Init(schema string, isProd bool) {
...
@@ -123,21 +123,21 @@ func Init(schema string, isProd bool) {
}
}
func
AddAsync
(
ctx
context
.
Context
,
traceNo
,
operate
string
,
req
*
entity
.
CopyHttpReq
,
rsp
*
entity
.
CopyHttpRsp
)
{
func
AddAsync
(
ctx
context
.
Context
,
traceNo
,
operate
string
,
req
*
entity
.
CopyHttpReq
,
rsp
*
entity
.
CopyHttpRsp
)
{
op
:=
&
WebLog
{}
wl
:=
&
WebLog
{}
op
.
ID
=
xsf
.
GenerateID
()
wl
.
ID
=
xsf
.
GenerateID
()
op
.
CompanyID
=
ctxUtils
.
GetCtxCompanyID
(
ctx
)
wl
.
CompanyID
=
ctxUtils
.
GetCtxCompanyID
(
ctx
)
op
.
UserID
=
ctxUtils
.
GetCtxUID
(
ctx
)
wl
.
UserID
=
ctxUtils
.
GetCtxUID
(
ctx
)
op
.
TraceID
=
ctxUtils
.
GetCtxTid
(
ctx
)
wl
.
TraceID
=
ctxUtils
.
GetCtxTid
(
ctx
)
op
.
Operate
=
operate
wl
.
Operate
=
operate
op
.
CreatedAt
=
xtime
.
Now
()
wl
.
CreatedAt
=
xtime
.
Now
()
if
req
!=
nil
{
if
req
!=
nil
{
op
.
Req
=
jsonU
tils
.
ToJSONStringPtr
(
req
)
wl
.
Req
=
json_u
tils
.
ToJSONStringPtr
(
req
)
}
}
if
rsp
!=
nil
{
if
rsp
!=
nil
{
op
.
Rsp
=
jsonU
tils
.
ToJSONStringPtr
(
rsp
)
wl
.
Rsp
=
json_u
tils
.
ToJSONStringPtr
(
rsp
)
}
}
go
func
()
{
go
func
()
{
merger
.
Add
(
op
)
merger
.
Add
(
wl
)
}()
}()
}
}
...
@@ -179,10 +179,6 @@ const TBWebLog = "web_log"
...
@@ -179,10 +179,6 @@ const TBWebLog = "web_log"
func
(
WebLog
)
TableName
()
string
{
func
(
WebLog
)
TableName
()
string
{
return
TBWebLog
return
TBWebLog
}
}
func
(
x
WebLog
)
GetOrder
()
string
{
return
"id asc"
}
func
(
x
*
WebLog
)
BeforeCreate
(
tx
*
gorm
.
DB
)
(
err
error
)
{
func
(
x
*
WebLog
)
BeforeCreate
(
tx
*
gorm
.
DB
)
(
err
error
)
{
if
x
.
CreatedAt
.
IsZero
()
{
if
x
.
CreatedAt
.
IsZero
()
{
x
.
CreatedAt
=
xtime
.
Now
()
x
.
CreatedAt
=
xtime
.
Now
()
...
...
utils/webLogUtils/weblog.sql
浏览文件 @
ea1c2441
...
@@ -2,8 +2,8 @@ DROP TABLE if EXISTS `web_log`;
...
@@ -2,8 +2,8 @@ DROP TABLE if EXISTS `web_log`;
CREATE
TABLE
`web_log`
(
CREATE
TABLE
`web_log`
(
`id`
bigint
(
20
)
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'ID eg[10001]'
,
`id`
bigint
(
20
)
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'ID eg[10001]'
,
`company_id`
bigint
(
20
)
unsigned
DEFAULT
NULL
COMMENT
'公司ID eg[20001]'
,
`company_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'公司ID eg[20001]'
,
`user_id`
bigint
(
20
)
unsigned
DEFAULT
NULL
COMMENT
'用户ID eg[30001]'
,
`user_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'用户ID eg[30001]'
,
`operate`
varchar
(
32
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
DEFAULT
''
COMMENT
'操作 eg[用户登出]'
,
`operate`
varchar
(
32
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
DEFAULT
''
COMMENT
'操作 eg[用户登出]'
,
`trace_id`
varchar
(
64
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
DEFAULT
''
COMMENT
'溯源id eg[TRACE_ID12345]'
,
`trace_id`
varchar
(
64
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
DEFAULT
''
COMMENT
'溯源id eg[TRACE_ID12345]'
,
`req`
json
DEFAULT
NULL
COMMENT
'请求 eg[]'
,
`req`
json
DEFAULT
NULL
COMMENT
'请求 eg[]'
,
...
...
utils/xtime/datetime.go
浏览文件 @
ea1c2441
...
@@ -77,8 +77,6 @@ func NowPtr() *DateTime {
...
@@ -77,8 +77,6 @@ func NowPtr() *DateTime {
return
&
j
return
&
j
}
}
const
TimeFormat
=
"2006-01-02 15:04:05"
// Value insert timestamp into mysql need this function.
// Value insert timestamp into mysql need this function.
func
(
t
DateTime
)
Value
()
(
driver
.
Value
,
error
)
{
func
(
t
DateTime
)
Value
()
(
driver
.
Value
,
error
)
{
var
zeroTime
time
.
Time
var
zeroTime
time
.
Time
...
...
utils/xtime/xtime.tmp.go
deleted
100644 → 0
浏览文件 @
e06545fc
差异被折叠。
点击展开。
utils/xtime/xtime.tmp_test.go
deleted
100644 → 0
浏览文件 @
e06545fc
package
xtime
import
(
"testing"
"time"
)
func
TestParseExtendedDuration
(
t
*
testing
.
T
)
{
type
args
struct
{
s
string
}
tests
:=
[]
struct
{
name
string
args
args
want
time
.
Duration
wantErr
bool
}{
{
name
:
"1"
,
args
:
args
{
s
:
"1d"
},
want
:
24
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"2"
,
args
:
args
{
s
:
"2w"
},
want
:
2
*
7
*
24
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"3"
,
args
:
args
{
s
:
"3M"
},
want
:
3
*
30
*
24
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"4"
,
args
:
args
{
s
:
"4y"
},
want
:
4
*
365
*
24
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"5"
,
args
:
args
{
s
:
"1d2h"
},
want
:
26
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"6"
,
args
:
args
{
s
:
"1W3D"
},
want
:
(
7
+
3
)
*
24
*
time
.
Hour
,
wantErr
:
false
},
{
name
:
"7"
,
args
:
args
{
s
:
"30m"
},
want
:
30
*
time
.
Minute
,
wantErr
:
false
},
{
name
:
"7"
,
args
:
args
{
s
:
"20s"
},
want
:
20
*
time
.
Second
,
wantErr
:
false
},
{
name
:
"7"
,
args
:
args
{
s
:
"20ms"
},
want
:
20
*
time
.
Millisecond
,
wantErr
:
false
},
{
name
:
"8"
,
args
:
args
{
s
:
"1x"
},
want
:
0
,
wantErr
:
true
},
{
name
:
"9"
,
args
:
args
{
s
:
"invalid"
},
want
:
0
,
wantErr
:
true
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
,
err
:=
ParseExtendedDuration
(
tt
.
args
.
s
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"ParseExtendedDuration() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
got
!=
tt
.
want
{
t
.
Errorf
(
"ParseExtendedDuration() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
xcommon/controller.go
浏览文件 @
ea1c2441
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/map
U
tils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/map
_u
tils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator"
)
)
...
@@ -102,7 +102,7 @@ func (x *ControllerTester) After(t *testing.T) {
...
@@ -102,7 +102,7 @@ func (x *ControllerTester) After(t *testing.T) {
func
(
x
*
ControllerTester
)
CommonHttp
(
method
,
URL
string
,
in
any
,
reply
*
response
.
Result
)
error
{
func
(
x
*
ControllerTester
)
CommonHttp
(
method
,
URL
string
,
in
any
,
reply
*
response
.
Result
)
error
{
if
method
==
http
.
MethodDelete
||
method
==
http
.
MethodGet
{
if
method
==
http
.
MethodDelete
||
method
==
http
.
MethodGet
{
in
=
map
U
tils
.
StructToMapWithJsonTag
(
in
)
in
=
map
_u
tils
.
StructToMapWithJsonTag
(
in
)
}
}
if
err
:=
x
.
client
.
NewRequest
()
.
if
err
:=
x
.
client
.
NewRequest
()
.
SetHeaders
(
x
.
Headers
)
.
SetHeaders
(
x
.
Headers
)
.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论