Commit cc5ef839 authored by Cloud User's avatar Cloud User

Revert "add error msg"

This reverts commit e98d09c0.
parent e98d09c0
cache @ dd268a4a
Subproject commit dd268a4a9e7c33d4551b961c665ca7cff69ab1a3
......@@ -10,22 +10,16 @@ import (
)
type apiQueryTxsForAddr struct {
uuid string
//res chan pbUpstream.TaskResponse
res chan ResWithError
uuid string
res chan pbUpstream.TaskResponse
async bool
}
type ResWithError struct {
res pbUpstream.TaskResponse
err error
}
var ApiQueryTxsByAddrForQueue = make(chan apiQueryTxsForAddr, 1000)
func syncReq(uuid string) chan ResWithError {
func syncReq(uuid string) chan pbUpstream.TaskResponse {
res := make(chan ResWithError)
res := make(chan pbUpstream.TaskResponse)
ApiQueryTxsByAddrForQueue <- apiQueryTxsForAddr{
uuid: uuid,
......@@ -47,24 +41,23 @@ func asyncReq(uuid string) {
}
// func callbackRes(res pbUpstream.TaskResponse) {
func callbackRes(res ResWithError) {
func callbackRes(res pbUpstream.TaskResponse) {
if v, ok := recordmap.LoadAndDelete(res.res.TaskId); ok {
if v, ok := recordmap.LoadAndDelete(res.TaskId); ok {
//resAsV, ok := v.(chan pbUpstream.TaskResponse)
resAsV, ok := v.(apiQueryTxsForAddr)
if ok {
if !resAsV.async {
resAsV.res <- res
} else {
asyncmap.Add(res.res.TaskId, res)
asyncmap.Add(res.TaskId, res)
//asyncmap.Store(res.TaskId, res)
}
}
}
}
func getAsyncRes(uuid string) (ResWithError, bool) {
func getAsyncRes(uuid string) (pbUpstream.TaskResponse, bool) {
return asyncmap.Get(uuid)
......@@ -79,11 +72,11 @@ func getAsyncRes(uuid string) (ResWithError, bool) {
var recordmap sync.Map
var asyncmap *expirable.LRU[string, ResWithError]
var asyncmap *expirable.LRU[string, pbUpstream.TaskResponse]
func init() {
asyncmap = expirable.NewLRU[string, ResWithError](10000000, nil, time.Hour*1)
asyncmap = expirable.NewLRU[string, pbUpstream.TaskResponse](10000000, nil, time.Hour*1)
}
func recordUUID() {
......
......@@ -49,8 +49,6 @@ RUN cat ./go-kafka/id_rsa > /root/.ssh/id_rsa && \
#RUN go build -o /go-kafka
RUN cd go-kafka && go mod tidy && make build-docker-ouput
COPY ./docs/ /docs/
#go build -o /ai-api-mgr
......@@ -59,7 +57,6 @@ FROM alpine
WORKDIR /root
COPY --from=build /ai-api-mgr /usr/bin/ai-api-mgr
COPY --from=build /docs /usr/bin/docs/
#ENTRYPOINT [ "/usr/bin/ai-api-mgr" ]
......
swagger: '2.0'
info:
title: feature.proto
version: version not set
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
#host: 192.168.1.220:8080
host: api.aigic.ai
#URL: "https://api.aigic.ai/swagger.yaml",
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
name: authorization
ApiKeyAuth: # arbitrary name for the security scheme
type: apiKey
in: header # can be "header", "query" or "cookie"
name: apiKey # name of the header, query parameter or cookie
paths:
/query/v1/{taskid}:
get:
summary: get /query/v1/{taskid}
responses:
'200':
description: ''
schema:
$ref: '#/definitions/normalResponseJsonObject'
parameters:
- name: taskid
in: path
required: true
type: string
format: uuid
/api/v1/{subPath}:
post:
security:
- ApiKeyAuth: []
summary: post /api/v1/txt2img/sd-1.5/base
responses:
'200':
description: ''
schema:
$ref: '#/definitions/normalResponseJsonObject'
parameters:
- name: subPath
in: path
required: true
type: string
format: url
- in: header
name: apikey
type: string
required: true
/api/v1/{subPath} async:
post:
security:
- ApiKeyAuth: []
summary: post /api/v1/txt2img/sd-1.5/base async
responses:
'200':
description: ''
schema:
$ref: '#/definitions/syncResponseObject'
parameters:
- name: subPath
in: path
required: true
type: string
format: url
- in: header
name: apikey
type: string
required: true
- in: header
name: Prefer
type: string
default: respond-async
required: true
/jwt/v1/{subPath}:
post:
security:
- bearerAuth: []
summary: post /jwt/v1/txt2img/sd-1.5/base
responses:
'200':
description: ''
schema:
$ref: '#/definitions/normalResponseJsonObject'
parameters:
- name: subPath
in: path
required: true
type: string
format: url
- in: header
name: authorization
type: string
required: true
/jwt/v1/{subPath} async:
post:
security:
- bearerAuth: []
summary: post /jwt/v1/txt2img/sd-1.5/base
responses:
'200':
description: ''
schema:
$ref: '#/definitions/syncResponseObject'
parameters:
- name: subPath
in: path
required: true
type: string
format: url
- in: header
name: authorization
type: string
required: true
- in: header
name: Prefer
type: string
default: respond-async
required: true
/callback/v1/:
post:
summary: post /callback/v1/
responses:
'200':
description: ''
requestBody:
required: true
schema:
$ref: '#/definitions/callbackReq'
definitions:
syncResponseObject:
type: object
properties:
task_id:
type: string
format: uuid
request_id:
type: string
estimate_exec_time:
type: integer
max_exec_time:
type: integer
normalResponseJsonObject:
type: object
properties:
output:
$ref: '#/definitions/output'
task:
$ref: '#/definitions/ResponseTask'
output:
type: object
description: |-
`output JSON object Struct` represents a structured data value for upstream
ResponseTask:
type: object
properties:
task_id:
type: string
format: uuid
task_uid:
type: integer
task_fee:
type: string
is_success:
type: boolean
task_error:
type: string
exec_code:
type: string
exec_error:
type: string
api_error:
type: string
enum:[
- "No + TaskIdKey + key found in request header"
- "No + RequestIdKey + " key found in request header"
- "No + TaskIdKey + value found in request header"
- "No + RequestIdKey + " value found in request header"
- "No + UIDkey + key found in request header"
- "No + UIDkey + value found in request header"
- "Uid value strconv atoi error is: \%s"
- "Query db error is: \%s"
- "Json marshal db content error is: \%s"
- "Can not find out the task id %s in result cache.""
- "Msg to kafka pb marshal error is: \%s"
- "sync call back error is: \%s"
- "sync response json marshal error is: \%s"
- "Callback proto unmarshal http body error is: \%s"
- "callback errror is: %s"
- "Http header in callback body marshal error is: %s"
- "Sync Or Async Return Json Unmarshal Error is: %s"
- "Task Return Json Marshal Error is: %s"
]
callbackReq:
protobufValue:
type: object
properties:
TaskId:
type: string
format: uuid
description: Represents task id.
TaskResultHeader:
type: string
format: byte
description: Represents a upstream http header in callback http body.
TaskResultBody:
type: string
format: byte
description: Represents a upstream http body in callback http body.
TaskUid:
type: string
TaskFee:
type: string
TaskIsSucceed:
type: boolean
format: boolean
TaskError:
type: string
format: string
TaskResultCode:
type: integer
TaskExecuteError:
type: string
format: string
\ No newline at end of file
contact: {}
paths: {}
swagger: "2.0"
......@@ -42,7 +42,6 @@ require (
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gofiber/swagger v1.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
......@@ -91,7 +90,6 @@ require (
github.com/samber/slog-loki/v3 v3.2.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
......
......@@ -569,8 +569,6 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/UE=
github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/swagger v1.0.0 h1:BzUzDS9ZT6fDUa692kxmfOjc1DZiloLiPK/W5z1H1tc=
github.com/gofiber/swagger v1.0.0/go.mod h1:QrYNF1Yrc7ggGK6ATsJ6yfH/8Zi5bu9lA7wB8TmCecg=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
......@@ -1239,8 +1237,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
......
This diff is collapsed.
odysseus-protocol @ b244b62f
Subproject commit b244b62f56e09c656f20a54d379bdde6f5b7ef3d
service-registry @ da2187b2
Subproject commit da2187b223a251b7e6049e0ee3a7951bdca76bee
package main
import (
"encoding/json"
"errors"
"strconv"
)
// const TaskIdAtrr = "Task-Id"
// const RequestId = "X-Kong-Request-Id"
// const UIDkey = "X-Consumer-Custom-Id"
const TaskIdKey = "Task-Id"
const RequestIdKey = "X-Kong-Request-Id"
const UIDkey = "X-Consumer-Custom-Id"
func checkRequestIdInHttpHeader(reqHeaders map[string][]string) (string, error) {
if RequestIdHeaders, ok := reqHeaders[RequestIdKey]; ok {
if RequestIdHeaders == nil || len(RequestIdHeaders) == 0 {
return "", errors.New(NoRequestIdKeyFoundInHeader)
} else {
return RequestIdHeaders[0], nil
}
} else {
return "", errors.New(NoRequestIdValueFoundInHeader)
}
}
func checkTaskIdInHttpHeader(reqHeaders map[string][]string) (string, error) {
if RequestIdHeaders, ok := reqHeaders[TaskIdKey]; ok {
if RequestIdHeaders == nil || len(RequestIdHeaders) == 0 {
return "", errors.New(NoTaskIdKeyFoundInHeader)
} else {
return RequestIdHeaders[0], nil
}
} else {
return "", errors.New(NoTaskIdValueFoundInHeader)
}
}
func checkUIDInHttpHeader(reqHeaders map[string][]string) (int, error) {
if RequestIdHeaders, ok := reqHeaders[UIDkey]; ok {
if RequestIdHeaders == nil || len(RequestIdHeaders) == 0 {
return 0, errors.New(NoTaskIdKeyFoundInHeader)
} else {
uidAsInt, err := strconv.Atoi(RequestIdHeaders[0])
if err != nil {
return 0, errors.New(UidValueStrconvAtoiError + err.Error())
}
return uidAsInt, nil
}
} else {
return 0, errors.New(NoUidValueFoundInHeader)
}
}
type ErrorMsg string
/*
- "No + TaskIdKey + key found in request header"
- "No + RequestIdKey + " key found in request header"
- "No + TaskIdKey + value found in request header"
- "No + RequestIdKey + " value found in request header"
- "No + UIDkey + key found in request header"
- "No + UIDkey + value found in request header"
- "Uid value strconv atoi error is: \%s"
- "Query db error is: \%s"
- "Json marshal db content error is: \%s"
- "Can not find out the task id %s in result cache.""
- "Msg to kafka pb marshal error is: \%s"
- "sync call back error is: \%s"
- "sync response json marshal error is: \%s"
- "Callback proto unmarshal http body error is: \%s"
- "callback errror is: %s"
- "Http header in callback body marshal error is: %s"
- "Sync Or Async Return Json Unmarshal Error is: %s"
- "Task Return Json Marshal Error is: %s"
*/
const (
//http headers
NoTaskIdKeyFoundInHeader = "No " + TaskIdKey + " key found in request header"
NoRequestIdKeyFoundInHeader = "No " + RequestIdKey + " key found in request header"
NoTaskIdValueFoundInHeader = "No " + TaskIdKey + " value found in request header"
NoRequestIdValueFoundInHeader = "No " + RequestIdKey + " value found in request header"
NoUidKeyFoundInHeader = "No " + UIDkey + " key found in request header"
NoUidValueFoundInHeader = "No " + UIDkey + " value found in request header"
UidValueStrconvAtoiError = "Uid value strconv atoi error is: %s"
QueryDbError = "Query db error is: %s"
JsonMarshalDbContentError = "Json marshal db content error is: %s"
QueryTaskByIdError = "Can not find out the task id %s in result cache."
MsgToKafakaPbMarshalError = "Msg to kafka pb marshal error is: %s"
//call back
SynCallBackError = "Sync call back error is: %s"
SyncResponseJsonMarshalError = "Sync response json marshal error is: %s"
//callback
CallbackPbUnmarshalError = "Callback proto unmarshal http body error is: %s"
CallbackError = "Callback errror is: %s"
HttpHeaderInCallbackBodyMarshalError = "Http header in callback body marshal error is: %s"
//return ApiErrorF(c, fmt.Sprintf("cache.Query %v", err.Error()), baseAttributes)
//sync or async return
SyncOrAsyncReturnJsonUnmarshalError = "Sync Or Async Return Json Unmarshal Error is %s"
//return
TaskReturnJsonMarshalError = "Task Return Json Marshal Error is %s"
)
type ResponseJson struct {
Task ResponseTask `json:"task"`
Output json.RawMessage `json:"output"`
}
type ResponseTask struct {
TaskId string `json:"task_id"`
//TaskResult []byte `json:"task_result"`
TaskUid string `json:"task_uid"`
TaskFee string `json:"task_fee"`
IsSuccess bool `json:"is_success"`
TaskError string `json:"task_error"`
ExecCode string `json:"exec_code"`
//ExecCode int32 `json:"exec_code"`
// "exec_code":"",
ExecError string `json:"exec_error"`
//Api ApiError `json:"api"`
ApiError ApiError `json:"api_error"`
}
type ApiError struct {
RequestId string `json:"request_id"`
Msg string `json:"message"`
}
func NewError(msg, requestId string) ApiError {
return ApiError{
RequestId: requestId,
Msg: msg,
}
}
type SyncResponse struct {
TaskId string `json:"task_id"`
RequestId string `json:"request_id"`
EstimateExecTime int `json:"estimate_exec_time"`
MaxExecTime int `json:"max_exec_time"`
}
// {
// "message": "No API key found in request",
// "request_id": "fc567d7a9bd52a5f157d820627266c57"
// }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment