Fix Pagination variable from *int64 to int64
parent
1c0e37928e
commit
f283f05671
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
22
mastodon.go
22
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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue