Improve code reuse

This commit is contained in:
video-prize-ranch
2022-05-23 11:10:50 -04:00
parent 5569feb2c8
commit 6eee86d682
7 changed files with 65 additions and 90 deletions

View File

@@ -1,8 +1,6 @@
package api
import (
"io"
"net/http"
"strings"
"sync"
"time"
@@ -22,18 +20,11 @@ func FetchComments(galleryID string) ([]types.Comment, error) {
return cacheData.([]types.Comment), nil
}
res, err := http.Get("https://api.imgur.com/comment/v1/comments?client_id=" + utils.Config["imgurId"].(string) + "&filter[post]=eq:" + galleryID + "&include=account,adconfig&per_page=30&sort=best")
data, err := utils.GetJSON("https://api.imgur.com/comment/v1/comments?client_id=" + utils.Config["imgurId"].(string) + "&filter[post]=eq:" + galleryID + "&include=account,adconfig&per_page=30&sort=best")
if err != nil {
return []types.Comment{}, err
return []types.Comment{}, nil
}
body, err := io.ReadAll(res.Body)
if err != nil {
return []types.Comment{}, err
}
data := gjson.Parse(string(body))
wg := sync.WaitGroup{}
comments := make([]types.Comment, 0)
data.Get("data").ForEach(