From f283f056710f363cb6ba99d2b5425f178fa93501 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sun, 7 May 2017 01:36:25 +0900 Subject: [PATCH] Fix Pagination variable from *int64 to int64 --- cmd/mstdn/cmd_followers.go | 4 ++-- helper.go | 3 --- helper_test.go | 8 ------- mastodon.go | 22 +++++++++---------- mastodon_test.go | 44 +++++++++++++++++++------------------- 5 files changed, 35 insertions(+), 46 deletions(-) diff --git a/cmd/mstdn/cmd_followers.go b/cmd/mstdn/cmd_followers.go index d505137..1d34a12 100644 --- a/cmd/mstdn/cmd_followers.go +++ b/cmd/mstdn/cmd_followers.go @@ -17,7 +17,7 @@ func cmdFollowers(c *cli.Context) error { if err != nil { return err } - var maxID *int64 + var maxID int64 var followers []*mastodon.Account for { pg := mastodon.Pagination{MaxID: maxID} @@ -26,7 +26,7 @@ func cmdFollowers(c *cli.Context) error { return err } followers = append(followers, fs...) - if pg.MaxID == nil { + if pg.MaxID == 0 { break } maxID = pg.MaxID diff --git a/helper.go b/helper.go index 281f5a2..05af20f 100644 --- a/helper.go +++ b/helper.go @@ -37,9 +37,6 @@ func Base64Encode(file *os.File) (string, error) { ";base64," + base64.StdEncoding.EncodeToString(d), nil } -// Int64 is a helper function to get the pointer value of a int64. -func Int64(v int64) *int64 { return &v } - // String is a helper function to get the pointer value of a string. func String(v string) *string { return &v } diff --git a/helper_test.go b/helper_test.go index b2599e6..7da80b9 100644 --- a/helper_test.go +++ b/helper_test.go @@ -62,14 +62,6 @@ func TestBase64Encode(t *testing.T) { } } -func TestInt64(t *testing.T) { - i := int64(1234567) - ip := Int64(i) - if *ip != i { - t.Fatalf("want %d but %d", i, *ip) - } -} - func TestString(t *testing.T) { s := "test" sp := String(s) diff --git a/mastodon.go b/mastodon.go index 1ac6029..1729597 100644 --- a/mastodon.go +++ b/mastodon.go @@ -213,9 +213,9 @@ type Results struct { // Pagination is a struct for specifying the get range. type Pagination struct { - MaxID *int64 - SinceID *int64 - Limit *int64 + MaxID int64 + SinceID int64 + Limit int64 } func newPagination(rawlink string) (*Pagination, error) { @@ -231,13 +231,13 @@ func newPagination(rawlink string) (*Pagination, error) { if err != nil { return nil, err } - p.MaxID = &maxID + p.MaxID = maxID case "prev": sinceID, err := getPaginationID(link.URL, "since_id") if err != nil { return nil, err } - p.SinceID = &sinceID + p.SinceID = sinceID } } @@ -263,14 +263,14 @@ func (p *Pagination) toValues() url.Values { } func (p *Pagination) setValues(params url.Values) url.Values { - if p.MaxID != nil { - params.Set("max_id", fmt.Sprint(*p.MaxID)) + if p.MaxID != 0 { + params.Set("max_id", fmt.Sprint(p.MaxID)) } - if p.SinceID != nil { - params.Set("since_id", fmt.Sprint(*p.SinceID)) + if p.SinceID != 0 { + params.Set("since_id", fmt.Sprint(p.SinceID)) } - if p.Limit != nil { - params.Set("limit", fmt.Sprint(*p.Limit)) + if p.Limit != 0 { + params.Set("limit", fmt.Sprint(p.Limit)) } return params diff --git a/mastodon_test.go b/mastodon_test.go index 974a380..eac42cd 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -25,26 +25,26 @@ func TestDoAPI(t *testing.T) { c := NewClient(&Config{Server: ts.URL}) var accounts []Account err := c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, &Pagination{ - MaxID: Int64(999), + MaxID: 999, }) if err == nil { t.Fatalf("should be fail: %v", err) } pg := &Pagination{ - MaxID: Int64(123), - SinceID: Int64(789), - Limit: Int64(10), + MaxID: 123, + SinceID: 789, + Limit: 10, } err = c.doAPI(context.Background(), http.MethodGet, "/", url.Values{}, &accounts, pg) if err != nil { t.Fatalf("should not be fail: %v", err) } - if *pg.MaxID != 234 { - t.Fatalf("want %d but %d", 234, *pg.MaxID) + if pg.MaxID != 234 { + t.Fatalf("want %d but %d", 234, pg.MaxID) } - if *pg.SinceID != 890 { - t.Fatalf("want %d but %d", 890, *pg.SinceID) + if pg.SinceID != 890 { + t.Fatalf("want %d but %d", 890, pg.SinceID) } if accounts[0].Username != "foo" { t.Fatalf("want %q but %q", "foo", accounts[0].Username) @@ -54,19 +54,19 @@ func TestDoAPI(t *testing.T) { } pg = &Pagination{ - MaxID: Int64(123), - SinceID: Int64(789), - Limit: Int64(10), + MaxID: 123, + SinceID: 789, + Limit: 10, } err = c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, pg) if err != nil { t.Fatalf("should not be fail: %v", err) } - if *pg.MaxID != 234 { - t.Fatalf("want %d but %d", 234, *pg.MaxID) + if pg.MaxID != 234 { + t.Fatalf("want %d but %d", 234, pg.MaxID) } - if *pg.SinceID != 890 { - t.Fatalf("want %d but %d", 890, *pg.SinceID) + if pg.SinceID != 890 { + t.Fatalf("want %d but %d", 890, pg.SinceID) } if accounts[0].Username != "foo" { t.Fatalf("want %q but %q", "foo", accounts[0].Username) @@ -297,11 +297,11 @@ func TestNewPagination(t *testing.T) { if err != nil { t.Fatalf("should not be fail: %v", err) } - if *pg.MaxID != 123 { - t.Fatalf("want %d but %d", 123, *pg.MaxID) + if pg.MaxID != 123 { + t.Fatalf("want %d but %d", 123, pg.MaxID) } - if *pg.SinceID != 789 { - t.Fatalf("want %d but %d", 789, *pg.SinceID) + if pg.SinceID != 789 { + t.Fatalf("want %d but %d", 789, pg.SinceID) } } @@ -327,9 +327,9 @@ func TestGetPaginationID(t *testing.T) { func TestPaginationSetValues(t *testing.T) { p := &Pagination{ - MaxID: Int64(123), - SinceID: Int64(789), - Limit: Int64(10), + MaxID: 123, + SinceID: 789, + Limit: 10, } before := url.Values{"key": {"value"}} after := p.setValues(before)