Fix Pagination variable from *int64 to int64
This commit is contained in:
parent
1c0e37928e
commit
f283f05671
|
@ -17,7 +17,7 @@ func cmdFollowers(c *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var maxID *int64
|
var maxID int64
|
||||||
var followers []*mastodon.Account
|
var followers []*mastodon.Account
|
||||||
for {
|
for {
|
||||||
pg := mastodon.Pagination{MaxID: maxID}
|
pg := mastodon.Pagination{MaxID: maxID}
|
||||||
|
@ -26,7 +26,7 @@ func cmdFollowers(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
followers = append(followers, fs...)
|
followers = append(followers, fs...)
|
||||||
if pg.MaxID == nil {
|
if pg.MaxID == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
maxID = pg.MaxID
|
maxID = pg.MaxID
|
||||||
|
|
|
@ -37,9 +37,6 @@ func Base64Encode(file *os.File) (string, error) {
|
||||||
";base64," + base64.StdEncoding.EncodeToString(d), nil
|
";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.
|
// String is a helper function to get the pointer value of a string.
|
||||||
func String(v string) *string { return &v }
|
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) {
|
func TestString(t *testing.T) {
|
||||||
s := "test"
|
s := "test"
|
||||||
sp := String(s)
|
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.
|
// Pagination is a struct for specifying the get range.
|
||||||
type Pagination struct {
|
type Pagination struct {
|
||||||
MaxID *int64
|
MaxID int64
|
||||||
SinceID *int64
|
SinceID int64
|
||||||
Limit *int64
|
Limit int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPagination(rawlink string) (*Pagination, error) {
|
func newPagination(rawlink string) (*Pagination, error) {
|
||||||
|
@ -231,13 +231,13 @@ func newPagination(rawlink string) (*Pagination, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.MaxID = &maxID
|
p.MaxID = maxID
|
||||||
case "prev":
|
case "prev":
|
||||||
sinceID, err := getPaginationID(link.URL, "since_id")
|
sinceID, err := getPaginationID(link.URL, "since_id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
func (p *Pagination) setValues(params url.Values) url.Values {
|
||||||
if p.MaxID != nil {
|
if p.MaxID != 0 {
|
||||||
params.Set("max_id", fmt.Sprint(*p.MaxID))
|
params.Set("max_id", fmt.Sprint(p.MaxID))
|
||||||
}
|
}
|
||||||
if p.SinceID != nil {
|
if p.SinceID != 0 {
|
||||||
params.Set("since_id", fmt.Sprint(*p.SinceID))
|
params.Set("since_id", fmt.Sprint(p.SinceID))
|
||||||
}
|
}
|
||||||
if p.Limit != nil {
|
if p.Limit != 0 {
|
||||||
params.Set("limit", fmt.Sprint(*p.Limit))
|
params.Set("limit", fmt.Sprint(p.Limit))
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
|
@ -25,26 +25,26 @@ func TestDoAPI(t *testing.T) {
|
||||||
c := NewClient(&Config{Server: ts.URL})
|
c := NewClient(&Config{Server: ts.URL})
|
||||||
var accounts []Account
|
var accounts []Account
|
||||||
err := c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, &Pagination{
|
err := c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, &Pagination{
|
||||||
MaxID: Int64(999),
|
MaxID: 999,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("should be fail: %v", err)
|
t.Fatalf("should be fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pg := &Pagination{
|
pg := &Pagination{
|
||||||
MaxID: Int64(123),
|
MaxID: 123,
|
||||||
SinceID: Int64(789),
|
SinceID: 789,
|
||||||
Limit: Int64(10),
|
Limit: 10,
|
||||||
}
|
}
|
||||||
err = c.doAPI(context.Background(), http.MethodGet, "/", url.Values{}, &accounts, pg)
|
err = c.doAPI(context.Background(), http.MethodGet, "/", url.Values{}, &accounts, pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
if *pg.MaxID != 234 {
|
if pg.MaxID != 234 {
|
||||||
t.Fatalf("want %d but %d", 234, *pg.MaxID)
|
t.Fatalf("want %d but %d", 234, pg.MaxID)
|
||||||
}
|
}
|
||||||
if *pg.SinceID != 890 {
|
if pg.SinceID != 890 {
|
||||||
t.Fatalf("want %d but %d", 890, *pg.SinceID)
|
t.Fatalf("want %d but %d", 890, pg.SinceID)
|
||||||
}
|
}
|
||||||
if accounts[0].Username != "foo" {
|
if accounts[0].Username != "foo" {
|
||||||
t.Fatalf("want %q but %q", "foo", accounts[0].Username)
|
t.Fatalf("want %q but %q", "foo", accounts[0].Username)
|
||||||
|
@ -54,19 +54,19 @@ func TestDoAPI(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pg = &Pagination{
|
pg = &Pagination{
|
||||||
MaxID: Int64(123),
|
MaxID: 123,
|
||||||
SinceID: Int64(789),
|
SinceID: 789,
|
||||||
Limit: Int64(10),
|
Limit: 10,
|
||||||
}
|
}
|
||||||
err = c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, pg)
|
err = c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
if *pg.MaxID != 234 {
|
if pg.MaxID != 234 {
|
||||||
t.Fatalf("want %d but %d", 234, *pg.MaxID)
|
t.Fatalf("want %d but %d", 234, pg.MaxID)
|
||||||
}
|
}
|
||||||
if *pg.SinceID != 890 {
|
if pg.SinceID != 890 {
|
||||||
t.Fatalf("want %d but %d", 890, *pg.SinceID)
|
t.Fatalf("want %d but %d", 890, pg.SinceID)
|
||||||
}
|
}
|
||||||
if accounts[0].Username != "foo" {
|
if accounts[0].Username != "foo" {
|
||||||
t.Fatalf("want %q but %q", "foo", accounts[0].Username)
|
t.Fatalf("want %q but %q", "foo", accounts[0].Username)
|
||||||
|
@ -297,11 +297,11 @@ func TestNewPagination(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
if *pg.MaxID != 123 {
|
if pg.MaxID != 123 {
|
||||||
t.Fatalf("want %d but %d", 123, *pg.MaxID)
|
t.Fatalf("want %d but %d", 123, pg.MaxID)
|
||||||
}
|
}
|
||||||
if *pg.SinceID != 789 {
|
if pg.SinceID != 789 {
|
||||||
t.Fatalf("want %d but %d", 789, *pg.SinceID)
|
t.Fatalf("want %d but %d", 789, pg.SinceID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,9 +327,9 @@ func TestGetPaginationID(t *testing.T) {
|
||||||
|
|
||||||
func TestPaginationSetValues(t *testing.T) {
|
func TestPaginationSetValues(t *testing.T) {
|
||||||
p := &Pagination{
|
p := &Pagination{
|
||||||
MaxID: Int64(123),
|
MaxID: 123,
|
||||||
SinceID: Int64(789),
|
SinceID: 789,
|
||||||
Limit: Int64(10),
|
Limit: 10,
|
||||||
}
|
}
|
||||||
before := url.Values{"key": {"value"}}
|
before := url.Values{"key": {"value"}}
|
||||||
after := p.setValues(before)
|
after := p.setValues(before)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user