Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
doc-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eifel邓鹏飞
doc-service
Commits
27d17e8a
Commit
27d17e8a
authored
Sep 26, 2024
by
Bess严根旺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回调请求
parent
9b790c8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
+34
-3
callback_command.go
console/callback_command.go
+34
-3
No files found.
console/callback_command.go
View file @
27d17e8a
...
...
@@ -7,6 +7,7 @@ import (
"doc-service/domain/entity/serversitemicros/docservercallback"
"doc-service/domain/entity/serversitemicros/docserverproject"
"doc-service/infra/db"
"encoding/json"
"errors"
"fmt"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
...
...
@@ -95,6 +96,17 @@ func callbackData(ctx context.Context) int8 {
return
1
}
// Data 结构体定义
type
BackData
struct
{
ID
int
`json:"id"`
Msg
string
`json:"msg"`
Status
int8
`json:"status"`
}
type
CallBackData
struct
{
ID
int
}
// 执行请求
func
callBackUrl
(
c
context
.
Context
,
projectId
int32
)
(
bool
,
string
)
{
defer
recoverPanicCallBack
()
...
...
@@ -121,14 +133,34 @@ func callBackUrl(c context.Context, projectId int32) (bool, string) {
}
}
projectInfo
,
_
:=
db
.
GetServerSiteMicrosDB
()
.
DocServerProject
.
Query
()
.
Where
(
docserverproject
.
IDEQ
(
projectId
),
)
.
First
(
c
)
logger
.
Info
(
projectInfo
)
if
res
{
//回调
if
callInfo
.
CallbackType
==
0
{
body
:=
[]
byte
(
callInfo
.
CallbackData
)
// 创建一个 Data 结构体实例
data
:=
&
BackData
{}
id
:=
0
if
callInfo
.
CallbackData
!=
""
{
backData
:=
CallBackData
{}
body
:=
[]
byte
(
callInfo
.
CallbackData
)
_
=
json
.
Unmarshal
(
body
,
&
backData
)
id
=
backData
.
ID
}
data
.
ID
=
id
data
.
Msg
=
projectInfo
.
CallbackRes
data
.
Status
=
0
// 将结构体转换为 JSON 格式
jsonData
,
_
:=
json
.
Marshal
(
data
)
headers
:=
map
[
string
]
string
{
"Content-Type"
:
"application/json"
,
}
code
,
respBody
,
errs
:=
sendPostRequest
(
callInfo
.
CallbackURL
,
body
,
headers
)
code
,
respBody
,
errs
:=
sendPostRequest
(
callInfo
.
CallbackURL
,
[]
byte
(
jsonData
),
headers
)
if
code
!=
200
||
errs
!=
nil
{
msg
=
fmt
.
Sprintf
(
"post回调 : code = %d , 原因:%s"
,
code
,
errs
.
Error
())
res
=
false
...
...
@@ -142,7 +174,6 @@ func callBackUrl(c context.Context, projectId int32) (bool, string) {
}
logger
.
Info
(
"Response Body:"
,
string
(
respBody
))
}
}
return
res
,
msg
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment