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,15 +1,15 @@
package reddit
import (
"encoding/json"
"fmt"
"io"
"net/http"
"regexp"
"govd/enums"
"govd/models"
"govd/util"
"github.com/bytedance/sonic"
)
var (
@ -255,13 +255,9 @@ func GetRedditData(host string, slug string) (RedditResponse, error) {
return GetRedditData(altHost, slug)
}
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
var response RedditResponse
err = json.Unmarshal(body, &response)
decoder := sonic.ConfigFastest.NewDecoder(res.Body)
err = decoder.Decode(&response)
if err != nil {
return nil, fmt.Errorf("failed to parse response: %w", err)
}