51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package fetcher
|
|
|
|
// Minimal structs to decode Reddit search.json responses we care about.
|
|
// We only define the fields we need.
|
|
|
|
type APIResponse struct {
|
|
Kind string `json:"kind"`
|
|
Data struct {
|
|
Modhash string `json:"modhash"`
|
|
Dist int `json:"dist"`
|
|
Children []struct {
|
|
Kind string `json:"kind"`
|
|
Data JSONPost `json:"data"`
|
|
} `json:"children"`
|
|
After string `json:"after"`
|
|
Before string `json:"before"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
// JSONPost contains the fields extracted from each child.data in Reddit response.
|
|
// It mirrors a subset of Reddit's API.
|
|
|
|
type JSONPost struct {
|
|
ID string `json:"id"`
|
|
Subreddit string `json:"subreddit"`
|
|
Title string `json:"title"`
|
|
Author string `json:"author"`
|
|
CreatedUTC float64 `json:"created_utc"`
|
|
Score int `json:"score"`
|
|
NumComments int `json:"num_comments"`
|
|
Selftext string `json:"selftext"`
|
|
URL string `json:"url"`
|
|
Permalink string `json:"permalink"`
|
|
}
|
|
|
|
// jsonPost contains the fields extracted from each child.data in Reddit response.
|
|
// It mirrors a subset of Reddit's API.
|
|
|
|
type jsonPost struct {
|
|
ID string `json:"id"`
|
|
Subreddit string `json:"subreddit"`
|
|
Title string `json:"title"`
|
|
Author string `json:"author"`
|
|
CreatedUTC float64 `json:"created_utc"`
|
|
Score int `json:"score"`
|
|
NumComments int `json:"num_comments"`
|
|
Selftext string `json:"selftext"`
|
|
URL string `json:"url"`
|
|
Permalink string `json:"permalink"`
|
|
}
|