Remove Permalink string alias
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
fbf7df5fe9
commit
204fa9080e
6 changed files with 22 additions and 37 deletions
|
@ -14,7 +14,7 @@ var expectedCommentSubmitOrEdit = &Comment{
|
|||
ID: "test2",
|
||||
FullID: "t1_test2",
|
||||
ParentID: "t1_test",
|
||||
Permalink: "https://www.reddit.com/r/subreddit/comments/test1/some_thread/test2/",
|
||||
Permalink: "/r/subreddit/comments/test1/some_thread/test2/",
|
||||
|
||||
Body: "test comment",
|
||||
Author: "reddit_username",
|
||||
|
|
|
@ -17,7 +17,7 @@ var expectedListingPosts = []*Post{
|
|||
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 8, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
Permalink: "/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
URL: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
|
||||
Title: "This is a title",
|
||||
|
@ -47,7 +47,7 @@ var expectedListingComments = []*Comment{
|
|||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
ParentID: "t3_i2gvg4",
|
||||
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/g05v931/",
|
||||
Permalink: "/r/test/comments/i2gvg4/this_is_a_title/g05v931/",
|
||||
|
||||
Body: "Test comment",
|
||||
Author: "v_95",
|
||||
|
@ -91,7 +91,7 @@ var expectedListingPosts2 = []*Post{
|
|||
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 8, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
Permalink: "/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
URL: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
|
||||
|
||||
Title: "This is a title",
|
||||
|
@ -117,7 +117,7 @@ var expectedListingPosts2 = []*Post{
|
|||
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/i2gvs1/this_is_a_title/",
|
||||
Permalink: "/r/test/comments/i2gvs1/this_is_a_title/",
|
||||
URL: "http://example.com",
|
||||
|
||||
Title: "This is a title",
|
||||
|
|
14
post_test.go
14
post_test.go
|
@ -17,7 +17,7 @@ var expectedPostAndComments = &PostAndComments{
|
|||
Created: &Timestamp{time.Date(2020, 7, 18, 10, 26, 7, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/testpost/test/",
|
||||
Permalink: "/r/test/comments/testpost/test/",
|
||||
URL: "https://www.reddit.com/r/test/comments/testpost/test/",
|
||||
|
||||
Title: "Test",
|
||||
|
@ -44,7 +44,7 @@ var expectedPostAndComments = &PostAndComments{
|
|||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
ParentID: "t3_testpost",
|
||||
Permalink: "https://www.reddit.com/r/test/comments/testpost/test/testc1/",
|
||||
Permalink: "/r/test/comments/testpost/test/testc1/",
|
||||
|
||||
Body: "Hi",
|
||||
Author: "testuser",
|
||||
|
@ -71,7 +71,7 @@ var expectedPostAndComments = &PostAndComments{
|
|||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
ParentID: "t1_testc1",
|
||||
Permalink: "https://www.reddit.com/r/test/comments/testpost/test/testc2/",
|
||||
Permalink: "/r/test/comments/testpost/test/testc2/",
|
||||
|
||||
Body: "Hello",
|
||||
Author: "testuser",
|
||||
|
@ -107,7 +107,7 @@ var expectedEditedPost = &Post{
|
|||
Created: &Timestamp{time.Date(2020, 7, 23, 1, 24, 55, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(2020, 7, 23, 1, 42, 44, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/hw6l6a/test_title/",
|
||||
Permalink: "/r/test/comments/hw6l6a/test_title/",
|
||||
URL: "https://www.reddit.com/r/test/comments/hw6l6a/test_title/",
|
||||
|
||||
Title: "Test Title",
|
||||
|
@ -136,7 +136,7 @@ var expectedPost2 = &Post{
|
|||
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/i2gvs1/this_is_a_title/",
|
||||
Permalink: "/r/test/comments/i2gvs1/this_is_a_title/",
|
||||
URL: "http://example.com",
|
||||
|
||||
Title: "This is a title",
|
||||
|
@ -163,7 +163,7 @@ var expectedPostDuplicates = &Posts{
|
|||
Created: &Timestamp{time.Date(2018, 5, 18, 9, 10, 18, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/8kbs85/test/",
|
||||
Permalink: "/r/test/comments/8kbs85/test/",
|
||||
URL: "http://example.com",
|
||||
|
||||
Title: "test",
|
||||
|
@ -187,7 +187,7 @@ var expectedPostDuplicates = &Posts{
|
|||
Created: &Timestamp{time.Date(2011, 10, 16, 13, 26, 40, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/le1tc/test_to_see_if_this_fixes_the_problem_of_my_likes/",
|
||||
Permalink: "/r/test/comments/le1tc/test_to_see_if_this_fixes_the_problem_of_my_likes/",
|
||||
URL: "http://www.example.com",
|
||||
|
||||
Title: "Test to see if this fixes the problem of my \"likes\" from the last 7 months vanishing.",
|
||||
|
|
|
@ -18,7 +18,7 @@ var expectedPosts = &Posts{
|
|||
Created: &Timestamp{time.Date(2019, 1, 16, 5, 57, 51, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/agi5zf/test/",
|
||||
Permalink: "/r/test/comments/agi5zf/test/",
|
||||
URL: "https://www.reddit.com/r/test/comments/agi5zf/test/",
|
||||
|
||||
Title: "test",
|
||||
|
@ -44,7 +44,7 @@ var expectedPosts = &Posts{
|
|||
Created: &Timestamp{time.Date(2020, 7, 27, 0, 5, 10, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/test/comments/hyhquk/veggies/",
|
||||
Permalink: "/r/test/comments/hyhquk/veggies/",
|
||||
URL: "https://i.imgur.com/LrN2mPw.jpg",
|
||||
|
||||
Title: "Veggies",
|
||||
|
@ -158,7 +158,7 @@ var expectedSearchPosts = &Posts{
|
|||
Created: &Timestamp{time.Date(2020, 7, 26, 18, 14, 24, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/WatchPeopleDieInside/comments/hybow9/pregnancy_test/",
|
||||
Permalink: "/r/WatchPeopleDieInside/comments/hybow9/pregnancy_test/",
|
||||
URL: "https://v.redd.it/ra4qnt8bt8d51",
|
||||
|
||||
Title: "Pregnancy test",
|
||||
|
@ -180,7 +180,7 @@ var expectedSearchPosts = &Posts{
|
|||
Created: &Timestamp{time.Date(2020, 7, 7, 15, 19, 42, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/worldnews/comments/hmwhd7/brazilian_president_jair_bolsonaro_tests_positive/",
|
||||
Permalink: "/r/worldnews/comments/hmwhd7/brazilian_president_jair_bolsonaro_tests_positive/",
|
||||
URL: "https://www.theguardian.com/world/2020/jul/07/jair-bolsonaro-coronavirus-positive-test-brazil-president",
|
||||
|
||||
Title: "Brazilian president Jair Bolsonaro tests positive for coronavirus",
|
||||
|
|
23
things.go
23
things.go
|
@ -19,21 +19,6 @@ const (
|
|||
kindModAction = "modaction"
|
||||
)
|
||||
|
||||
// Permalink is the link to a post or comment.
|
||||
type Permalink string
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||
func (p *Permalink) UnmarshalJSON(data []byte) error {
|
||||
var v string
|
||||
err := json.Unmarshal(data, &v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v = "https://www.reddit.com" + v
|
||||
*p = Permalink(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// thing is an entity on Reddit.
|
||||
// Its kind reprsents what it is and what is stored in the Data field
|
||||
// e.g. t1 = comment, t2 = user, t3 = post, etc.
|
||||
|
@ -128,8 +113,8 @@ type Comment struct {
|
|||
Created *Timestamp `json:"created_utc,omitempty"`
|
||||
Edited *Timestamp `json:"edited,omitempty"`
|
||||
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
Permalink Permalink `json:"permalink,omitempty"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
Permalink string `json:"permalink,omitempty"`
|
||||
|
||||
Body string `json:"body,omitempty"`
|
||||
Author string `json:"author,omitempty"`
|
||||
|
@ -253,8 +238,8 @@ type Post struct {
|
|||
Created *Timestamp `json:"created_utc,omitempty"`
|
||||
Edited *Timestamp `json:"edited,omitempty"`
|
||||
|
||||
Permalink Permalink `json:"permalink,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Permalink string `json:"permalink,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
Title string `json:"title,omitempty"`
|
||||
Body string `json:"selftext,omitempty"`
|
||||
|
|
|
@ -52,7 +52,7 @@ var expectedPost = &Post{
|
|||
Created: &Timestamp{time.Date(2020, 5, 3, 22, 46, 25, 0, time.UTC)},
|
||||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
Permalink: "https://www.reddit.com/r/redditdev/comments/gczwql/get_userusernamegilded_does_it_return_other_users/",
|
||||
Permalink: "/r/redditdev/comments/gczwql/get_userusernamegilded_does_it_return_other_users/",
|
||||
URL: "https://www.reddit.com/r/redditdev/comments/gczwql/get_userusernamegilded_does_it_return_other_users/",
|
||||
|
||||
Title: "GET /user/{username}/gilded: does it return other user's things you've gilded, or your things that have been gilded? Does it return both comments and posts?",
|
||||
|
@ -81,7 +81,7 @@ var expectedComment = &Comment{
|
|||
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
ParentID: "t3_d7ejpn",
|
||||
Permalink: "https://www.reddit.com/r/apple/comments/d7ejpn/im_giving_away_an_iphone_11_pro_to_a_commenter_at/f0zsa37/",
|
||||
Permalink: "/r/apple/comments/d7ejpn/im_giving_away_an_iphone_11_pro_to_a_commenter_at/f0zsa37/",
|
||||
|
||||
Body: "Thank you!",
|
||||
Author: "v_95",
|
||||
|
|
Loading…
Reference in a new issue