Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
d08de9ac
提交
d08de9ac
authored
12月 22, 2025
作者:
mooncake
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
9afc8689
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
67 行增加
和
6 行删除
+67
-6
config.go
config/config.go
+25
-1
httpcli.go
pkg/httpcli/httpcli.go
+29
-1
oss.go
pkg/oss/oss.go
+3
-4
controller.go
xcommon/controller.go
+2
-0
go.go
xutils/goutils/go.go
+8
-0
没有找到文件。
config/config.go
浏览文件 @
d08de9ac
...
...
@@ -69,7 +69,6 @@ func GetOssConfig() *oss.AliOssConfig {
ossCfg
.
AccessKeySecret
=
c
.
Oss
.
AccessKeySecret
ossCfg
.
BucketName
=
c
.
Oss
.
BucketName
ossCfg
.
BasePath
=
c
.
Oss
.
BasePath
ossCfg
.
BucketUrl
=
c
.
Oss
.
BucketUrl
ossCfg
.
Region
=
c
.
Oss
.
Region
})
return
ossCfg
...
...
@@ -95,6 +94,7 @@ func Read(f func(c *Config)) {
func
IsNotProd
()
bool
{
return
!
IsProd
()
}
func
IsProd
()
bool
{
env
:=
"prod"
Read
(
func
(
c
*
Config
)
{
...
...
@@ -103,6 +103,30 @@ func IsProd() bool {
return
strings
.
ToLower
(
env
)
==
"prod"
}
func
IsNotTest
()
bool
{
return
!
IsTest
()
}
func
IsTest
()
bool
{
env
:=
"prod"
Read
(
func
(
c
*
Config
)
{
env
=
c
.
App
.
Env
})
return
strings
.
ToLower
(
env
)
==
"test"
}
func
IsNotMock
()
bool
{
return
!
IsMock
()
}
func
IsMock
()
bool
{
env
:=
"prod"
Read
(
func
(
c
*
Config
)
{
env
=
c
.
App
.
Env
})
return
strings
.
ToLower
(
env
)
==
"mock"
}
type
Config
struct
{
l
*
sync
.
RWMutex
App
App
`yaml:"app" json:"app" mapstructure:"app"`
...
...
pkg/httpcli/httpcli.go
浏览文件 @
d08de9ac
...
...
@@ -34,6 +34,7 @@ type Request struct {
reqBodyJSON
any
// 传入对象,会自动json marshal
timeout
time
.
Duration
// Client timeout
retryCount
int
retryBackoffDuration
time
.
Duration
request
*
http
.
Request
response
*
Response
...
...
@@ -144,10 +145,20 @@ func (x *Request) SetTimeout(t time.Duration) *Request {
x
.
timeout
=
t
return
x
}
func
(
x
*
Request
)
SetRetry
(
count
int
)
*
Request
{
x
.
retryCount
=
count
return
x
}
func
(
x
*
Request
)
SetRetryBackoffDuration
(
d
time
.
Duration
)
*
Request
{
if
d
<=
0
{
d
=
time
.
Second
}
x
.
retryBackoffDuration
=
d
return
x
}
func
(
x
*
Request
)
SetMethod
(
method
string
)
*
Request
{
x
.
method
=
method
return
x
...
...
@@ -324,12 +335,15 @@ func (x *Request) send(ctx context.Context) {
st
:=
time
.
Now
()
if
x
.
retryCount
>
0
{
if
x
.
retryBackoffDuration
<=
0
{
x
.
retryBackoffDuration
=
time
.
Second
}
x
.
err
=
retryutils
.
Retry
(
func
()
error
{
x
.
pushDo
(
ctx
)
return
x
.
err
},
retryutils
.
RetryTimes
(
uint
(
x
.
retryCount
)),
retryutils
.
RetryWithLinearBackoff
(
8
*
time
.
Second
),
retryutils
.
RetryWithLinearBackoff
(
x
.
retryBackoffDuration
),
retryutils
.
Context
(
ctx
),
)
}
else
{
...
...
@@ -466,6 +480,20 @@ func (x *Request) BindJSON(v any) *Request {
}
return
x
}
func
(
x
*
Request
)
BindJSONOpts
(
v
any
,
ignore
bool
)
*
Request
{
if
v
==
nil
{
return
x
}
if
x
.
err
!=
nil
{
return
x
}
if
err
:=
json
.
Unmarshal
(
x
.
response
.
body
,
v
);
err
!=
nil
{
if
!
ignore
{
x
.
err
=
err
}
}
return
x
}
// ----------------------------------- Request way 2 -----------------------------------
...
...
pkg/oss/oss.go
浏览文件 @
d08de9ac
...
...
@@ -20,7 +20,6 @@ type AliOssConfig struct {
AccessKeySecret
string
`mapstructure:"access-key-secret" json:"access-key-secret" yaml:"access-key-secret"`
BucketName
string
`mapstructure:"bucket-name" json:"bucket-name" yaml:"bucket-name"`
BasePath
string
`mapstructure:"base-path" json:"base-path" yaml:"base-path"`
BucketUrl
string
`mapstructure:"bucket-url" json:"bucket-url" yaml:"bucket-url"`
Region
string
`mapstructure:"region" json:"region" yaml:"region"`
}
...
...
@@ -54,7 +53,7 @@ func (*AliyunOSS) UploadFile(reader io.Reader, name string, cfg *AliOssConfig) (
if
err
!=
nil
{
return
""
,
""
,
xerror
.
NewNetError
(
err
.
Error
())
}
return
cfg
.
BucketUrl
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
return
"http://"
+
cfg
.
BucketName
+
"."
+
cfg
.
Endpoint
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
}
type
Attachment
struct
{
...
...
@@ -78,7 +77,7 @@ func (x Attachment) NewFromMultipartFileHeaders(files []*multipart.FileHeader) (
File
:
reader
,
Name
:
files
[
i
]
.
Filename
,
}
attachments
=
append
(
attachments
,
attachment
)
attachments
[
i
]
=
attachment
}
return
attachments
,
nil
}
...
...
@@ -113,7 +112,7 @@ func (*AliyunOSS) UploadFiles(files *[]*Attachment, cfg *AliOssConfig) error {
if
err
!=
nil
{
return
xerror
.
NewNetError
(
err
.
Error
())
}
(
*
files
)[
i
]
.
AbsUrl
=
cfg
.
BucketUrl
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
AbsUrl
=
"http://"
+
cfg
.
BucketName
+
"."
+
cfg
.
Endpoint
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
RelativeUrl
=
relativeUri
}
return
nil
...
...
xcommon/controller.go
浏览文件 @
d08de9ac
...
...
@@ -162,8 +162,10 @@ func (x *ControllerTester) After(t *testing.T) {
func
(
x
*
ControllerTester
)
CommonHttp
(
method
,
URL
string
,
in
any
,
reply
*
response
.
Result
)
error
{
if
method
==
http
.
MethodDelete
||
method
==
http
.
MethodGet
{
if
in
!=
nil
{
in
=
maputils
.
StructToMapWithJsonTag
(
in
)
}
}
if
err
:=
x
.
client
.
NewRequest
()
.
SetHeaders
(
x
.
Headers
)
.
SetURL
(
URL
)
.
SetContentType
(
"application/json"
)
.
...
...
xutils/goutils/go.go
浏览文件 @
d08de9ac
...
...
@@ -23,6 +23,14 @@ func RecoverCtx(ctx context.Context) {
}
}
// Go
// c := ctxutils.NewCtx(ctx)
//
// goutils.Go(c, func() {
// if e := x.afterCreate(c, biz.FeedbackTool.New(&feedback)); e != nil {
// logger.StartSpan(c).Errorf("after create failed,err: %s", err.Error())
// }
// })
func
Go
(
ctx
context
.
Context
,
f
func
())
{
go
func
()
{
defer
RecoverCtx
(
ctx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论