Added a request-url-template option for Reddit requests

Reddit blocks known datacenter IPs from accessing their endpoints unless you request them to unblock it. Even so it has a low chance of success.

The new option will allow users to specify a request URL to handle Reddit requests.
This commit is contained in:
Jaryl Chng
2024-04-30 09:21:33 +08:00
parent eb85a7656f
commit 24ef8f6e2a
3 changed files with 28 additions and 3 deletions

View File

@@ -30,8 +30,12 @@ type subredditResponseJson struct {
} `json:"data"`
}
func FetchSubredditPosts(subreddit string, commentsUrlTemplate string) (ForumPosts, error) {
requestUrl := fmt.Sprintf("https://www.reddit.com/r/%s/hot.json", url.QueryEscape(subreddit))
func FetchSubredditPosts(subreddit string, commentsUrlTemplate string, requestUrlTemplate string) (ForumPosts, error) {
subreddit = url.QueryEscape(subreddit)
requestUrl := fmt.Sprintf("https://www.reddit.com/r/%s/hot.json", subreddit)
if requestUrlTemplate != "" {
requestUrl = strings.ReplaceAll(requestUrlTemplate, "{REQUEST-URL}", requestUrl)
}
request, err := http.NewRequest("GET", requestUrl, nil)
if err != nil {