Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ai-api-mgr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Odysseus
ai-api-mgr
Commits
8a18f5dc
Commit
8a18f5dc
authored
Mar 19, 2024
by
Cloud User
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix json marshal
parent
26f9864a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
16 deletions
+30
-16
main.go
main.go
+30
-16
No files found.
main.go
View file @
8a18f5dc
package
main
package
main
import
(
import
(
"bytes"
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
...
@@ -598,7 +599,7 @@ func batchToQuestDb(done chan interface{}, reqStream chan pbUpstream.TaskContent
...
@@ -598,7 +599,7 @@ func batchToQuestDb(done chan interface{}, reqStream chan pbUpstream.TaskContent
type
ResponseJson
struct
{
type
ResponseJson
struct
{
Task
ResponseTask
`json:"task"`
Task
ResponseTask
`json:"task"`
Output
json
.
RawMessage
`json:"output"`
Output
json
.
RawMessage
`json:"output"`
}
}
type
ResponseTask
struct
{
type
ResponseTask
struct
{
...
@@ -984,7 +985,7 @@ func main() {
...
@@ -984,7 +985,7 @@ func main() {
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelInfo
,
"getAsyncRes"
,
newAttributes
...
)
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelInfo
,
"getAsyncRes"
,
newAttributes
...
)
return
syncOrAsyncReturn
(
c
,
res
,
taskId
)
return
syncOrAsyncReturn
(
c
,
res
,
taskId
,
baseAttributes
)
}
}
return
c
.
SendString
(
fmt
.
Sprintf
(
"can not find out the task id %s in result cache."
,
taskId
))
return
c
.
SendString
(
fmt
.
Sprintf
(
"can not find out the task id %s in result cache."
,
taskId
))
...
@@ -1277,10 +1278,10 @@ func syncModeF(c *fiber.Ctx, taskid string) error {
...
@@ -1277,10 +1278,10 @@ func syncModeF(c *fiber.Ctx, taskid string) error {
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelInfo
,
"syncModeF"
,
newAttributes
...
)
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelInfo
,
"syncModeF"
,
newAttributes
...
)
return
syncOrAsyncReturn
(
c
,
resAsPb
,
taskid
)
return
syncOrAsyncReturn
(
c
,
resAsPb
,
taskid
,
baseAttributes
)
}
}
func
syncOrAsyncReturn
(
c
*
fiber
.
Ctx
,
resAsPb
pbUpstream
.
TaskResponse
,
reqTaskId
string
)
error
{
func
syncOrAsyncReturn
(
c
*
fiber
.
Ctx
,
resAsPb
pbUpstream
.
TaskResponse
,
reqTaskId
string
,
baseAttributes
[]
slog
.
Attr
)
error
{
// 303 (See Other) responses always lead to the use of a GET method.
// 303 (See Other) responses always lead to the use of a GET method.
// 307 (Temporary Redirect) and 308 (Permanent Redirect) don't change the method used in the original request.
// 307 (Temporary Redirect) and 308 (Permanent Redirect) don't change the method used in the original request.
...
@@ -1336,11 +1337,11 @@ func syncOrAsyncReturn(c *fiber.Ctx, resAsPb pbUpstream.TaskResponse, reqTaskId
...
@@ -1336,11 +1337,11 @@ func syncOrAsyncReturn(c *fiber.Ctx, resAsPb pbUpstream.TaskResponse, reqTaskId
// return redirectReturn(c, resAsPb)
// return redirectReturn(c, resAsPb)
// }
// }
return
Return
(
c
,
resAsPb
)
return
Return
(
c
,
resAsPb
,
baseAttributes
)
}
}
func
Return
(
c
*
fiber
.
Ctx
,
resAsPb
pbUpstream
.
TaskResponse
)
error
{
func
Return
(
c
*
fiber
.
Ctx
,
resAsPb
pbUpstream
.
TaskResponse
,
baseAttributes
[]
slog
.
Attr
)
error
{
resAsJson
:=
ResponseJson
{
resAsJson
:=
ResponseJson
{
Task
:
ResponseTask
{
Task
:
ResponseTask
{
...
@@ -1349,22 +1350,35 @@ func Return(c *fiber.Ctx, resAsPb pbUpstream.TaskResponse) error {
...
@@ -1349,22 +1350,35 @@ func Return(c *fiber.Ctx, resAsPb pbUpstream.TaskResponse) error {
TaskFee
:
resAsPb
.
TaskFee
,
TaskFee
:
resAsPb
.
TaskFee
,
IsSuccess
:
resAsPb
.
TaskIsSucceed
,
IsSuccess
:
resAsPb
.
TaskIsSucceed
,
TaskError
:
resAsPb
.
TaskError
,
TaskError
:
resAsPb
.
TaskError
,
ExecCode
:
fmt
.
Sprintf
(
"%d"
,
resAsPb
.
TaskResultCode
),
//resAsPb.TaskResultCode,
ExecCode
:
fmt
.
Sprintf
(
"%d"
,
resAsPb
.
TaskResultCode
),
//resAsPb.TaskResultCode,
//TaskExecuteError
//TaskExecuteError
ExecError
:
resAsPb
.
TaskExecuteError
,
ExecError
:
resAsPb
.
TaskExecuteError
,
},
},
Output
:
resAsPb
.
GetTaskResultBody
(),
Output
:
resAsPb
.
GetTaskResultBody
(),
}
}
// resAsJson := ResponseJson{
resbuffer
:=
&
bytes
.
Buffer
{}
// TaskId: resAsPb.TaskId,
encoder
:=
json
.
NewEncoder
(
resbuffer
)
// TaskResult: resAsPb.GetTaskResultBody(),
encoder
.
SetEscapeHTML
(
false
)
// TaskUid: resAsPb.TaskUid,
// TaskFee: resAsPb.TaskFee,
//fileAsJsonEscapeHTML,err := EncodeJsonEscapeHTML(fileAsJsonBytes)
// IsSuccess: resAsPb.TaskIsSucceed,
// TaskError: resAsPb.TaskError,
if
err
:=
encoder
.
Encode
(
resAsJson
);
err
!=
nil
{
// //TaskResultCode: resAsPb.TaskResultCode,
newAttributes
:=
append
(
baseAttributes
,
slog
.
String
(
"err"
,
err
.
Error
()))
// }
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelError
,
"encoder.Encode(resAsJson)"
,
newAttributes
...
)
}
newAttributes
:=
append
(
baseAttributes
,
slog
.
String
(
"TaskId"
,
resAsJson
.
Task
.
TaskId
),
slog
.
String
(
"TaskUid"
,
resAsJson
.
Task
.
TaskUid
),
slog
.
String
(
"TaskFee"
,
resAsJson
.
Task
.
TaskFee
),
slog
.
Bool
(
"IsSuccess"
,
resAsJson
.
Task
.
IsSuccess
),
slog
.
String
(
"TaskError"
,
resAsJson
.
Task
.
TaskError
),
slog
.
String
(
"ExecCode"
,
resAsJson
.
Task
.
ExecCode
),
slog
.
String
(
"ExecError"
,
resAsJson
.
Task
.
ExecError
),
)
slog
.
LogAttrs
(
c
.
UserContext
(),
slog
.
LevelError
,
"http return"
,
newAttributes
...
)
return
c
.
JSON
(
resAsJson
)
return
c
.
JSON
(
resAsJson
)
...
...
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