Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
5c90f99a
提交
5c90f99a
authored
9月 09, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
5f7f8976
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
35 行增加
和
10 行删除
+35
-10
config.go
config/config.go
+7
-0
httpcli.go
httpcli/httpcli.go
+3
-3
dxsf.go
utils/dxsf/dxsf.go
+25
-7
没有找到文件。
config/config.go
浏览文件 @
5c90f99a
...
@@ -106,6 +106,7 @@ type Config struct {
...
@@ -106,6 +106,7 @@ type Config struct {
NacosRd
NacosRd
`yaml:"nacosRd" json:"nacosRd"`
NacosRd
NacosRd
`yaml:"nacosRd" json:"nacosRd"`
Redis
Redis
`yaml:"redis" json:"redis"`
Redis
Redis
`yaml:"redis" json:"redis"`
CronJobs
Cron
`yaml:"cron" json:"cron"`
CronJobs
Cron
`yaml:"cron" json:"cron"`
Leaf
Leaf
`yaml:"leaf" json:"leaf"`
NacosConfClient
*
NacosClient
`yaml:"-" json:"-"`
NacosConfClient
*
NacosClient
`yaml:"-" json:"-"`
NacosNamingClient
*
nacos
.
NacosNamingClient
`yaml:"-" json:"-"`
NacosNamingClient
*
nacos
.
NacosNamingClient
`yaml:"-" json:"-"`
AliOss
alioss
.
AliOssConfig
`yaml:"oss" json:"oss"`
AliOss
alioss
.
AliOssConfig
`yaml:"oss" json:"oss"`
...
@@ -364,6 +365,12 @@ type Cron struct {
...
@@ -364,6 +365,12 @@ type Cron struct {
Enable
bool
`yaml:"enable" json:"enable"`
Enable
bool
`yaml:"enable" json:"enable"`
}
}
type
Leaf
struct
{
Addr
string
`yaml:"addr" json:"addr"`
// eg http://leaf.qitu
ShowLog
bool
`yaml:"showLog" json:"showLog"`
RetryCount
int
`yaml:"retryCount" json:"retryCount"`
}
type
CronJob
struct
{
type
CronJob
struct
{
Name
string
`yaml:"name" json:"name"`
Name
string
`yaml:"name" json:"name"`
TimeSpec
string
`yaml:"timeSpec" json:"timeSpec"`
TimeSpec
string
`yaml:"timeSpec" json:"timeSpec"`
...
...
httpcli/httpcli.go
浏览文件 @
5c90f99a
...
@@ -32,7 +32,7 @@ type Request struct {
...
@@ -32,7 +32,7 @@ type Request struct {
reqBody
[]
byte
// Body data
reqBody
[]
byte
// Body data
reqBodyJSON
interface
{}
// 传入对象,会自动json marshal
reqBodyJSON
interface
{}
// 传入对象,会自动json marshal
timeout
time
.
Duration
// Client timeout
timeout
time
.
Duration
// Client timeout
retryCount
u
int
retryCount
int
request
*
http
.
Request
request
*
http
.
Request
response
*
Response
response
*
Response
...
@@ -143,7 +143,7 @@ func (x *Request) SetTimeout(t time.Duration) *Request {
...
@@ -143,7 +143,7 @@ func (x *Request) SetTimeout(t time.Duration) *Request {
x
.
timeout
=
t
x
.
timeout
=
t
return
x
return
x
}
}
func
(
x
*
Request
)
SetRetry
(
count
u
int
)
*
Request
{
func
(
x
*
Request
)
SetRetry
(
count
int
)
*
Request
{
x
.
retryCount
=
count
x
.
retryCount
=
count
return
x
return
x
}
}
...
@@ -327,7 +327,7 @@ func (x *Request) send(ctx context.Context) {
...
@@ -327,7 +327,7 @@ func (x *Request) send(ctx context.Context) {
x
.
pushDo
(
ctx
)
x
.
pushDo
(
ctx
)
return
x
.
err
return
x
.
err
},
},
retry
.
RetryTimes
(
x
.
retryCount
),
retry
.
RetryTimes
(
uint
(
x
.
retryCount
)
),
retry
.
RetryWithLinearBackoff
(
8
*
time
.
Second
),
retry
.
RetryWithLinearBackoff
(
8
*
time
.
Second
),
retry
.
Context
(
ctx
),
retry
.
Context
(
ctx
),
)
)
...
...
utils/dxsf/dxsf.go
浏览文件 @
5c90f99a
...
@@ -8,13 +8,17 @@ import (
...
@@ -8,13 +8,17 @@ import (
"os"
"os"
"time"
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
)
)
var
(
var
(
xsfAddr
string
=
"http://leaf.qitu"
retryCount
=
3
api
=
&
client
{
showLog
=
false
xsfAddr
string
=
"http://leaf.qitu"
api
=
&
client
{
cli
:
httpcli
.
NewClient
(
cli
:
httpcli
.
NewClient
(
&
http
.
Client
{
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
Transport
:
&
http
.
Transport
{
...
@@ -24,7 +28,6 @@ var (
...
@@ -24,7 +28,6 @@ var (
},
},
}),
}),
}
}
ErrNoXsfAddr
=
errors
.
New
(
"缺少环境变量XSF_ADDR"
)
)
)
type
client
struct
{
type
client
struct
{
...
@@ -35,17 +38,32 @@ func init() {
...
@@ -35,17 +38,32 @@ func init() {
if
addr
:=
os
.
Getenv
(
"XSF_ADDR"
);
addr
!=
""
{
if
addr
:=
os
.
Getenv
(
"XSF_ADDR"
);
addr
!=
""
{
xsfAddr
=
addr
xsfAddr
=
addr
}
}
if
config
.
Cfg
.
Leaf
.
Addr
!=
""
{
xsfAddr
=
config
.
Cfg
.
Leaf
.
Addr
}
config
.
Read
(
func
(
c
*
config
.
Config
)
{
if
c
.
Leaf
.
ShowLog
{
showLog
=
true
}
if
c
.
Leaf
.
RetryCount
>
0
{
retryCount
=
c
.
Leaf
.
RetryCount
}
})
}
}
func
GenerateApiID
(
ctx
context
.
Context
,
bizTag
string
)
(
xsf
.
ID
,
error
)
{
func
GenerateApiID
(
ctx
context
.
Context
,
bizTag
string
)
(
xsf
.
ID
,
error
)
{
url
:=
fmt
.
Sprintf
(
`%s/api/leaf?biz_tag=%s`
,
xsfAddr
,
bizTag
)
url
:=
fmt
.
Sprintf
(
`%s/api/leaf?biz_tag=%s`
,
xsfAddr
,
bizTag
)
var
id
xsf
.
ID
var
id
xsf
.
ID
reply
:=
&
IDReply
{
reply
:=
&
IDReply
{
Data
:
&
id
,
Data
:
&
id
,
}
}
if
err
:=
api
.
cli
.
NewRequest
()
.
OmitLog
()
.
SetRetry
(
3
)
.
req
:=
api
.
cli
.
NewRequest
()
// if err := api.cli.NewRequest().SetRetry(3).
if
!
showLog
{
SetContentType
(
"application/json"
)
.
SetURL
(
url
)
.
GET
(
ctx
)
.
BindJSON
(
reply
)
.
Err
();
err
!=
nil
{
req
=
req
.
OmitLog
()
return
xsf
.
ID
(
-
1
),
err
}
if
err
:=
req
.
SetRetry
(
retryCount
)
.
SetContentType
(
"application/json"
)
.
SetURL
(
url
)
.
GET
(
ctx
)
.
BindJSON
(
reply
)
.
Err
();
err
!=
nil
{
logger
.
Error
(
"调用leaf失败"
,
logger
.
String
(
"bizTag"
,
bizTag
),
logger
.
Err
(
err
))
return
xsf
.
ID
(
-
1
),
fmt
.
Errorf
(
"调用leaf失败, %w"
,
err
)
}
}
if
reply
.
Code
==
1
{
if
reply
.
Code
==
1
{
return
id
,
nil
return
id
,
nil
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论