Skip to content

utility to fetch list page by page and change the results to an iterator. 翻页数据转化为迭代器的神器。

License

Notifications You must be signed in to change notification settings

rosbit/list-fetcher

Repository files navigation

list-fetcher, a utility to fetch list page by page and change the results to an iterator

Interface to implement

import (
	"encoding/json"
)

type PageFetcher interface {
    GetNextPage() (total int64, list []json.RawMessage, err error)
    AdjustPage(list []json.RawMessage)
    HasMore() bool // called if total is 0
    ErrorOccurrs(err error)
}

Utility functions

func FetchList(pf PageFetcher) (total int64, it <-chan json.RawMessage, err error) {
    //
}

func Dump(w io.Writer, it <-chan json.RawMessage) {
    //
}
func DumpJSON(w io.Writer, it <-chan json.RawMessage) {
    //
}

Usage

See list-fetcher_test.go

About

utility to fetch list page by page and change the results to an iterator. 翻页数据转化为迭代器的神器。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages