From 1e1d79dabcfee2ac9fcb3c170bc85b1323ae8774 Mon Sep 17 00:00:00 2001 From: Vadimka Komissarov Date: Tue, 13 Aug 2024 02:33:23 +0900 Subject: [PATCH 1/3] apiv1 - fix expected number near offset --- internal/utils/apiv1_response.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/utils/apiv1_response.go b/internal/utils/apiv1_response.go index 9d463a0..2526b73 100644 --- a/internal/utils/apiv1_response.go +++ b/internal/utils/apiv1_response.go @@ -3,6 +3,7 @@ package utils import ( "io" "sync" + "strconv" "github.com/mailru/easyjson" ) @@ -22,7 +23,7 @@ type ( Code string } ApiError struct { - Code int + Code string Message string Description string } @@ -72,7 +73,7 @@ func RespondWithApiError(status int, msg, desc string, w io.Writer) (e error) { defer ReleaseApiResponse(apirsp) apirsp.Error.Code, apirsp.Error.Message, apirsp.Error.Description = - status, msg, desc + strconv.Itoa(status), msg, desc apirsp.Data = nil var buf []byte From 423732f675f9168d398a5bdbcd0b2ed9e9ec00f2 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:42:33 +0000 Subject: [PATCH 2/3] style: format code with Go fmt This commit fixes the style issues introduced in 1e1d79d according to the output from Go fmt. Details: https://github.com/anilibria/alice/pull/49 --- internal/utils/apiv1_response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/utils/apiv1_response.go b/internal/utils/apiv1_response.go index 2526b73..d05dc9c 100644 --- a/internal/utils/apiv1_response.go +++ b/internal/utils/apiv1_response.go @@ -2,8 +2,8 @@ package utils import ( "io" + "strconv" "sync" - "strconv" "github.com/mailru/easyjson" ) From 1dab62bb356370bba5a5c546dc9eb6704771d426 Mon Sep 17 00:00:00 2001 From: Vadimka Komissarov Date: Wed, 25 Sep 2024 13:44:46 +0000 Subject: [PATCH 3/3] bugfix --- internal/proxy/proxy.go | 4 ++-- internal/utils/apiv1_response.go | 4 ++-- internal/utils/apiv1_response_easyjson.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 67e91b3..e439af8 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -139,7 +139,7 @@ func (*Proxy) unmarshalApiResponse(c *fiber.Ctx, rsp *fasthttp.Response) (ok boo } defer utils.ReleaseApiResponseWOData(apirsp) - if apirsp.Status && (apirsp.Error == nil || apirsp.Error.Code == 0) { + if apirsp.Status && (apirsp.Error == nil || apirsp.Error.Code == "0") { ok = true return } @@ -160,7 +160,7 @@ func (*Proxy) unmarshalApiResponse(c *fiber.Ctx, rsp *fasthttp.Response) (ok boo rlog(c).Trace().Msgf("%+v", apirsp.Error) } - rlog(c).Info().Msgf("api server respond with %d - %s", apirsp.Error.Code, apirsp.Error.Message) + rlog(c).Info().Msgf("api server respond with %s - %s", apirsp.Error.Code, apirsp.Error.Message) return } diff --git a/internal/utils/apiv1_response.go b/internal/utils/apiv1_response.go index 2526b73..0e3ec9b 100644 --- a/internal/utils/apiv1_response.go +++ b/internal/utils/apiv1_response.go @@ -2,8 +2,8 @@ package utils import ( "io" + "strconv" "sync" - "strconv" "github.com/mailru/easyjson" ) @@ -43,7 +43,7 @@ func AcquireApiResponseWOData() *ApiResponseWOData { func ReleaseApiResponseWOData(ar *ApiResponseWOData) { ar.Status = false - ar.Error.Code, ar.Error.Message, ar.Error.Description = 0, "", "" + ar.Error.Code, ar.Error.Message, ar.Error.Description = "", "", "" apiResponseWODataPool.Put(ar) } diff --git a/internal/utils/apiv1_response_easyjson.go b/internal/utils/apiv1_response_easyjson.go index 99f0793..f6ed21a 100644 --- a/internal/utils/apiv1_response_easyjson.go +++ b/internal/utils/apiv1_response_easyjson.go @@ -292,7 +292,7 @@ func easyjson1e840bfDecodeGithubComAnilibriaAliceInternalUtils3(in *jlexer.Lexer } switch key { case "code": - out.Code = int(in.Int()) + out.Code = string(in.String()) case "message": out.Message = string(in.String()) case "description": @@ -314,7 +314,7 @@ func easyjson1e840bfEncodeGithubComAnilibriaAliceInternalUtils3(out *jwriter.Wri { const prefix string = ",\"code\":" out.RawString(prefix[1:]) - out.Int(int(in.Code)) + out.String(string(in.Code)) } { const prefix string = ",\"message\":"