Remove "before" field from Response

Listing responses only ever contain a non-empty "before" field when the
"count" parameter is provided, which is only useful for the HTML
website, not really needed for API clients

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-09-29 14:19:32 -04:00
parent 15ee94fbbe
commit d128a7c4f7
6 changed files with 7 additions and 59 deletions
+1 -20
View File
@@ -31,7 +31,6 @@ const (
type anchor interface {
After() string
Before() string
}
// thing is an entity on Reddit.
@@ -53,17 +52,6 @@ func (t *thing) After() string {
return a.After()
}
func (t *thing) Before() string {
if t == nil {
return ""
}
a, ok := t.Data.(anchor)
if !ok {
return ""
}
return a.Before()
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (t *thing) UnmarshalJSON(b []byte) error {
root := new(struct {
@@ -239,27 +227,21 @@ func (t *thing) StyleSheet() (v *SubredditStyleSheet, ok bool) {
}
// listing is a list of things coming from the Reddit API.
// It also contains the after/before anchors useful for subsequent requests.
// It also contains the after anchor useful to get the next results via subsequent requests.
type listing struct {
things things
after string
before string
}
func (l *listing) After() string {
return l.after
}
func (l *listing) Before() string {
return l.before
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (l *listing) UnmarshalJSON(b []byte) error {
root := new(struct {
Things things `json:"children"`
After string `json:"after"`
Before string `json:"before"`
})
err := json.Unmarshal(b, root)
@@ -269,7 +251,6 @@ func (l *listing) UnmarshalJSON(b []byte) error {
l.things = root.Things
l.after = root.After
l.before = root.Before
return nil
}