From b1d2d6719fef34c125aec3c080d057151e02d7a1 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sun, 14 May 2017 04:40:19 +0900 Subject: [PATCH] Add ExamplePagination --- example_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/example_test.go b/example_test.go index 9b7c879..eda78b8 100644 --- a/example_test.go +++ b/example_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "time" "github.com/mattn/go-mastodon" ) @@ -40,3 +41,27 @@ func ExampleClient() { fmt.Println(timeline[i]) } } + +func ExamplePagination() { + c := mastodon.NewClient(&mastodon.Config{ + Server: "https://mstdn.jp", + ClientID: "client-id", + ClientSecret: "client-secret", + }) + var followers []*mastodon.Account + var pg mastodon.Pagination + for { + fs, err := c.GetAccountFollowers(context.Background(), 1, &pg) + if err != nil { + log.Fatal(err) + } + followers = append(followers, fs...) + if pg.MaxID == 0 { + break + } + time.Sleep(10 * time.Second) + } + for _, f := range followers { + fmt.Println(f.Acct) + } +}