Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base Client: support custom paging #587

Merged
merged 6 commits into from
Aug 9, 2023
Merged

Base Client: support custom paging #587

merged 6 commits into from
Aug 9, 2023

Conversation

manicminer
Copy link
Contributor

@manicminer manicminer commented Aug 1, 2023

Fixes: #492

Importer/generator will need to be updated to output custom pagers for APIs that require it.

Custom pagers could look something like this (note the pager is responsible for clearing its own state after returning a link, to be ready for the next page):

var _ odata.CustomPager = &pager{}

type pager struct {
	NextLink *odata.Link `json:"nextLink"`
}

func (p *pager) NextPageLink() *odata.Link {
	if p == nil {
		return nil
	}
	defer func() { p.NextLink = nil }()
	return p.NextLink
}

which you'd include in the RequestOptions, e.g:

opts := client.RequestOptions{
	ContentType: "application/json; charset=utf-8",
	ExpectedStatusCodes: []int{
		http.StatusOK,
	},
	HttpMethod:    http.MethodGet,
	Pager:         &pager{},
	Path:          fmt.Sprintf("%s/machines", id.ID()),
	OptionsObject: options,
}

@manicminer manicminer requested a review from a team as a code owner August 1, 2023 14:39
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments but otherwise 👍

sdk/odata/paging.go Show resolved Hide resolved
sdk/odata/paging.go Outdated Show resolved Hide resolved
@manicminer manicminer merged commit f0fed54 into main Aug 9, 2023
@manicminer manicminer deleted the f/custom-paging branch August 9, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate @ 2020-01-01 - support for nonstandard next link
2 participants