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 个修改的文件
包含
77 行增加
和
16 行删除
+77
-16
config.go
config/config.go
+25
-1
httpcli.go
pkg/httpcli/httpcli.go
+38
-10
oss.go
pkg/oss/oss.go
+3
-4
controller.go
xcommon/controller.go
+3
-1
go.go
xutils/goutils/go.go
+8
-0
没有找到文件。
config/config.go
浏览文件 @
d08de9ac
...
@@ -69,7 +69,6 @@ func GetOssConfig() *oss.AliOssConfig {
...
@@ -69,7 +69,6 @@ func GetOssConfig() *oss.AliOssConfig {
ossCfg
.
AccessKeySecret
=
c
.
Oss
.
AccessKeySecret
ossCfg
.
AccessKeySecret
=
c
.
Oss
.
AccessKeySecret
ossCfg
.
BucketName
=
c
.
Oss
.
BucketName
ossCfg
.
BucketName
=
c
.
Oss
.
BucketName
ossCfg
.
BasePath
=
c
.
Oss
.
BasePath
ossCfg
.
BasePath
=
c
.
Oss
.
BasePath
ossCfg
.
BucketUrl
=
c
.
Oss
.
BucketUrl
ossCfg
.
Region
=
c
.
Oss
.
Region
ossCfg
.
Region
=
c
.
Oss
.
Region
})
})
return
ossCfg
return
ossCfg
...
@@ -95,6 +94,7 @@ func Read(f func(c *Config)) {
...
@@ -95,6 +94,7 @@ func Read(f func(c *Config)) {
func
IsNotProd
()
bool
{
func
IsNotProd
()
bool
{
return
!
IsProd
()
return
!
IsProd
()
}
}
func
IsProd
()
bool
{
func
IsProd
()
bool
{
env
:=
"prod"
env
:=
"prod"
Read
(
func
(
c
*
Config
)
{
Read
(
func
(
c
*
Config
)
{
...
@@ -103,6 +103,30 @@ func IsProd() bool {
...
@@ -103,6 +103,30 @@ func IsProd() bool {
return
strings
.
ToLower
(
env
)
==
"prod"
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
{
type
Config
struct
{
l
*
sync
.
RWMutex
l
*
sync
.
RWMutex
App
App
`yaml:"app" json:"app" mapstructure:"app"`
App
App
`yaml:"app" json:"app" mapstructure:"app"`
...
...
pkg/httpcli/httpcli.go
浏览文件 @
d08de9ac
...
@@ -25,15 +25,16 @@ import (
...
@@ -25,15 +25,16 @@ import (
const
defaultTimeout
=
60
*
time
.
Second
const
defaultTimeout
=
60
*
time
.
Second
type
Request
struct
{
type
Request
struct
{
cli
*
http
.
Client
cli
*
http
.
Client
url
string
url
string
method
string
method
string
headers
map
[
string
]
string
headers
map
[
string
]
string
params
map
[
string
]
any
// parameters after URL
params
map
[
string
]
any
// parameters after URL
reqBody
[]
byte
// Body data
reqBody
[]
byte
// Body data
reqBodyJSON
any
// 传入对象,会自动json marshal
reqBodyJSON
any
// 传入对象,会自动json marshal
timeout
time
.
Duration
// Client timeout
timeout
time
.
Duration
// Client timeout
retryCount
int
retryCount
int
retryBackoffDuration
time
.
Duration
request
*
http
.
Request
request
*
http
.
Request
response
*
Response
response
*
Response
...
@@ -144,10 +145,20 @@ func (x *Request) SetTimeout(t time.Duration) *Request {
...
@@ -144,10 +145,20 @@ func (x *Request) SetTimeout(t time.Duration) *Request {
x
.
timeout
=
t
x
.
timeout
=
t
return
x
return
x
}
}
func
(
x
*
Request
)
SetRetry
(
count
int
)
*
Request
{
func
(
x
*
Request
)
SetRetry
(
count
int
)
*
Request
{
x
.
retryCount
=
count
x
.
retryCount
=
count
return
x
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
{
func
(
x
*
Request
)
SetMethod
(
method
string
)
*
Request
{
x
.
method
=
method
x
.
method
=
method
return
x
return
x
...
@@ -324,12 +335,15 @@ func (x *Request) send(ctx context.Context) {
...
@@ -324,12 +335,15 @@ func (x *Request) send(ctx context.Context) {
st
:=
time
.
Now
()
st
:=
time
.
Now
()
if
x
.
retryCount
>
0
{
if
x
.
retryCount
>
0
{
if
x
.
retryBackoffDuration
<=
0
{
x
.
retryBackoffDuration
=
time
.
Second
}
x
.
err
=
retryutils
.
Retry
(
func
()
error
{
x
.
err
=
retryutils
.
Retry
(
func
()
error
{
x
.
pushDo
(
ctx
)
x
.
pushDo
(
ctx
)
return
x
.
err
return
x
.
err
},
},
retryutils
.
RetryTimes
(
uint
(
x
.
retryCount
)),
retryutils
.
RetryTimes
(
uint
(
x
.
retryCount
)),
retryutils
.
RetryWithLinearBackoff
(
8
*
time
.
Second
),
retryutils
.
RetryWithLinearBackoff
(
x
.
retryBackoffDuration
),
retryutils
.
Context
(
ctx
),
retryutils
.
Context
(
ctx
),
)
)
}
else
{
}
else
{
...
@@ -466,6 +480,20 @@ func (x *Request) BindJSON(v any) *Request {
...
@@ -466,6 +480,20 @@ func (x *Request) BindJSON(v any) *Request {
}
}
return
x
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 -----------------------------------
// ----------------------------------- Request way 2 -----------------------------------
...
...
pkg/oss/oss.go
浏览文件 @
d08de9ac
...
@@ -20,7 +20,6 @@ type AliOssConfig struct {
...
@@ -20,7 +20,6 @@ type AliOssConfig struct {
AccessKeySecret
string
`mapstructure:"access-key-secret" json:"access-key-secret" yaml:"access-key-secret"`
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"`
BucketName
string
`mapstructure:"bucket-name" json:"bucket-name" yaml:"bucket-name"`
BasePath
string
`mapstructure:"base-path" json:"base-path" yaml:"base-path"`
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"`
Region
string
`mapstructure:"region" json:"region" yaml:"region"`
}
}
...
@@ -54,7 +53,7 @@ func (*AliyunOSS) UploadFile(reader io.Reader, name string, cfg *AliOssConfig) (
...
@@ -54,7 +53,7 @@ func (*AliyunOSS) UploadFile(reader io.Reader, name string, cfg *AliOssConfig) (
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
xerror
.
NewNetError
(
err
.
Error
())
return
""
,
""
,
xerror
.
NewNetError
(
err
.
Error
())
}
}
return
cfg
.
BucketUrl
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
return
"http://"
+
cfg
.
BucketName
+
"."
+
cfg
.
Endpoint
+
"/"
+
fileTmpPath
,
fileTmpPath
,
nil
}
}
type
Attachment
struct
{
type
Attachment
struct
{
...
@@ -78,7 +77,7 @@ func (x Attachment) NewFromMultipartFileHeaders(files []*multipart.FileHeader) (
...
@@ -78,7 +77,7 @@ func (x Attachment) NewFromMultipartFileHeaders(files []*multipart.FileHeader) (
File
:
reader
,
File
:
reader
,
Name
:
files
[
i
]
.
Filename
,
Name
:
files
[
i
]
.
Filename
,
}
}
attachments
=
append
(
attachments
,
attachment
)
attachments
[
i
]
=
attachment
}
}
return
attachments
,
nil
return
attachments
,
nil
}
}
...
@@ -113,7 +112,7 @@ func (*AliyunOSS) UploadFiles(files *[]*Attachment, cfg *AliOssConfig) error {
...
@@ -113,7 +112,7 @@ func (*AliyunOSS) UploadFiles(files *[]*Attachment, cfg *AliOssConfig) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
xerror
.
NewNetError
(
err
.
Error
())
return
xerror
.
NewNetError
(
err
.
Error
())
}
}
(
*
files
)[
i
]
.
AbsUrl
=
cfg
.
BucketUrl
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
AbsUrl
=
"http://"
+
cfg
.
BucketName
+
"."
+
cfg
.
Endpoint
+
"/"
+
relativeUri
(
*
files
)[
i
]
.
RelativeUrl
=
relativeUri
(
*
files
)[
i
]
.
RelativeUrl
=
relativeUri
}
}
return
nil
return
nil
...
...
xcommon/controller.go
浏览文件 @
d08de9ac
...
@@ -162,7 +162,9 @@ func (x *ControllerTester) After(t *testing.T) {
...
@@ -162,7 +162,9 @@ 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
=
maputils
.
StructToMapWithJsonTag
(
in
)
if
in
!=
nil
{
in
=
maputils
.
StructToMapWithJsonTag
(
in
)
}
}
}
if
err
:=
x
.
client
.
NewRequest
()
.
if
err
:=
x
.
client
.
NewRequest
()
.
SetHeaders
(
x
.
Headers
)
.
SetHeaders
(
x
.
Headers
)
.
...
...
xutils/goutils/go.go
浏览文件 @
d08de9ac
...
@@ -23,6 +23,14 @@ func RecoverCtx(ctx context.Context) {
...
@@ -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
())
{
func
Go
(
ctx
context
.
Context
,
f
func
())
{
go
func
()
{
go
func
()
{
defer
RecoverCtx
(
ctx
)
defer
RecoverCtx
(
ctx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论