Skip to content

Commit 7298f19

Browse files
committed
feat: get rid of ffjson
1 parent ed39afb commit 7298f19

35 files changed

+122
-60798
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.22.3
44

55
require (
66
github.com/bots-go-framework/bots-go-core v0.0.3
7-
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
87
github.com/stretchr/testify v1.10.0
98
github.com/strongo/logus v0.2.1
109
github.com/technoweenie/multipartstreamer v1.0.1

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1313
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1414
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1515
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
16-
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20=
17-
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
1816
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
1917
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
20-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
21-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2218
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
2319
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
24-
github.com/strongo/logus v0.2.0 h1:IbLupLW9WMIwjefJF+u9/Ajlaw6ysFuEeKQxOFX5tOE=
25-
github.com/strongo/logus v0.2.0/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
2620
github.com/strongo/logus v0.2.1 h1:ZzAtdSg6PPF1Y43WbNWl7MH1XYl7kvKMxyxv/lpbadI=
2721
github.com/strongo/logus v0.2.1/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
2822
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=

tgbotapi/bot_api.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package tgbotapi
55
import (
66
"bytes"
77
"context"
8+
"encoding/json"
89
"errors"
910
"fmt"
10-
"github.com/pquerna/ffjson/ffjson"
1111
"github.com/strongo/logus"
1212
"github.com/technoweenie/multipartstreamer"
1313
"io"
@@ -130,7 +130,7 @@ func (bot *BotAPI) MakeRequest(telegramMethod string, params url.Values) (apiRes
130130
}
131131
}
132132

133-
if err = ffjson.Unmarshal(apiResp.Result, &apiResp); err != nil {
133+
if err = json.Unmarshal(apiResp.Result, &apiResp); err != nil {
134134
logRequestAndResponse()
135135
return apiResp, fmt.Errorf("telegram API returned non JSON response or unknown JSON: %w:\n%s", err, string(apiResp.Result))
136136
} else if !apiResp.Ok {
@@ -162,7 +162,7 @@ func (bot *BotAPI) makeMessageRequest(endpoint string, params url.Values) (Messa
162162
}
163163

164164
if string(resp.Result) != "true" { // TODO: This is a workaround for "answerCallbackQuery" that returns just "true".
165-
if err = ffjson.Unmarshal(resp.Result, &message); err != nil {
165+
if err = json.Unmarshal(resp.Result, &message); err != nil {
166166
return message, fmt.Errorf("failed to call json.Unmarshal(s): %w: s=%s", err, string(resp.Result))
167167
}
168168
}
@@ -255,7 +255,7 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
255255
logus.Debugf(bot.c, string(body))
256256
}
257257

258-
if err = ffjson.Unmarshal(body, &apiResp); err != nil {
258+
if err = json.Unmarshal(body, &apiResp); err != nil {
259259
return
260260
}
261261

@@ -292,7 +292,7 @@ func (bot *BotAPI) GetMe() (User, error) {
292292
return user, err
293293
}
294294

295-
if err = ffjson.Unmarshal(resp.Result, &user); err != nil {
295+
if err = json.Unmarshal(resp.Result, &user); err != nil {
296296
return user, err
297297
}
298298

@@ -309,7 +309,7 @@ func (bot *BotAPI) GetChat(chatID string) (Chat, error) {
309309
return chat, err
310310
}
311311

312-
if err = ffjson.Unmarshal(resp.Result, &chat); err != nil {
312+
if err = json.Unmarshal(resp.Result, &chat); err != nil {
313313
return chat, err
314314
}
315315

@@ -379,7 +379,7 @@ func (bot *BotAPI) uploadAndSend(method string, config Fileable) (Message, error
379379
return message, err
380380
}
381381

382-
if err = ffjson.Unmarshal(resp.Result, &message); err != nil {
382+
if err = json.Unmarshal(resp.Result, &message); err != nil {
383383
return message, err
384384
}
385385

@@ -429,7 +429,7 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
429429
return profilePhotos, err
430430
}
431431

432-
if err = ffjson.Unmarshal(resp.Result, &profilePhotos); err != nil {
432+
if err = json.Unmarshal(resp.Result, &profilePhotos); err != nil {
433433
return profilePhotos, err
434434
}
435435

@@ -452,7 +452,7 @@ func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
452452
return file, err
453453
}
454454

455-
if err = ffjson.Unmarshal(resp.Result, &file); err != nil {
455+
if err = json.Unmarshal(resp.Result, &file); err != nil {
456456
return file, err
457457
}
458458

@@ -487,7 +487,7 @@ func (bot *BotAPI) GetUpdates(config *UpdateConfig) ([]Update, error) {
487487
return updates, err
488488
}
489489

490-
if err = ffjson.Unmarshal(resp.Result, &updates); err != nil {
490+
if err = json.Unmarshal(resp.Result, &updates); err != nil {
491491
return updates, err
492492
}
493493

@@ -520,7 +520,7 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
520520
return apiResp, err
521521
}
522522

523-
if err = ffjson.Unmarshal(resp.Result, &apiResp); err != nil {
523+
if err = json.Unmarshal(resp.Result, &apiResp); err != nil {
524524
return apiResp, err
525525
}
526526

@@ -567,7 +567,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update {
567567
body, _ := io.ReadAll(r.Body)
568568

569569
var update Update
570-
if err := ffjson.Unmarshal(body, &update); err != nil {
570+
if err := json.Unmarshal(body, &update); err != nil {
571571
logus.Errorf(context.Background(), fmt.Errorf("failed to unmarshal update JSON: %w", err).Error())
572572
return
573573
}
@@ -595,23 +595,19 @@ func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
595595
v.Add("next_offset", config.NextOffset)
596596
}
597597

598-
data, err := ffjson.Marshal(config.Results)
598+
data, err := encodeToJson(config.Results)
599599
if err != nil {
600-
ffjson.Pool(data)
601600
return APIResponse{}, err
602601
}
603602
v.Add("results", string(data))
604603

605604
if config.Button != nil {
606-
if data, err = ffjson.Marshal(config.Button); err != nil {
607-
ffjson.Pool(data)
605+
if data, err = encodeToJson(config.Button); err != nil {
608606
return APIResponse{}, err
609607
}
610608
v.Add("button", string(data))
611609
}
612610

613-
ffjson.Pool(data)
614-
615611
bot.debugLog("answerInlineQuery", v, nil)
616612

617613
return bot.MakeRequest("answerInlineQuery", v)
@@ -680,7 +676,7 @@ func (bot *BotAPI) SendCustomMessage(ctx context.Context, config Sendable, resul
680676
if err != nil {
681677
return
682678
}
683-
if err = ffjson.Unmarshal(apiResponse.Result, &result); err != nil {
679+
if err = json.Unmarshal(apiResponse.Result, &result); err != nil {
684680
err = fmt.Errorf("failed to unmarshal telegram response to type %T: %s: %w", result, string(apiResponse.Result), err)
685681
return
686682
}

0 commit comments

Comments
 (0)