implement sonic for json + remove some TODOs from readme + fix go version requirement (#5)

This commit is contained in:
dogghi no 2025-04-17 14:16:30 +02:00 committed by GitHub
parent 4a15dd0761
commit e35bd2fe57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 70 additions and 47 deletions

View file

@ -1,9 +1,7 @@
package pinterest
import (
"encoding/json"
"fmt"
"io"
"net/http"
"regexp"
"strings"
@ -11,6 +9,8 @@ import (
"govd/enums"
"govd/models"
"govd/util"
"github.com/bytedance/sonic"
)
const (
@ -185,13 +185,9 @@ func GetPinData(pinID string) (*PinData, error) {
return nil, fmt.Errorf("bad response: %s", resp.Status)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
var pinResponse PinResponse
err = json.Unmarshal(body, &pinResponse)
decoder := sonic.ConfigFastest.NewDecoder(resp.Body)
err = decoder.Decode(&pinResponse)
if err != nil {
return nil, fmt.Errorf("failed to parse response: %w", err)
}

View file

@ -1,11 +1,12 @@
package pinterest
import (
"encoding/json"
"fmt"
"govd/enums"
"govd/models"
"govd/util/parser"
"github.com/bytedance/sonic"
)
func ParseVideoObject(videoObj *Videos) ([]*models.MediaFormat, error) {
@ -48,7 +49,7 @@ func BuildPinRequestParams(pinID string) map[string]string {
},
}
jsonData, _ := json.Marshal(options)
jsonData, _ := sonic.ConfigFastest.Marshal(options)
return map[string]string{
"data": string(jsonData),
}