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

Implements PageSize to requests #160

Merged
merged 1 commit into from
Aug 27, 2020
Merged

Implements PageSize to requests #160

merged 1 commit into from
Aug 27, 2020

Conversation

phillc
Copy link
Contributor

@phillc phillc commented Aug 27, 2020

It did not feel right scripting the creation of minimum page size + 1 records to test this. I made a quick script to test it manually.

package main

import (
	"context"
	"fmt"

	"github.com/linode/linodego"
	"golang.org/x/oauth2"

	"log"
	"net/http"
	"os"
)

func main() {
	apiKey, ok := os.LookupEnv("LINODE_TOKEN")
	if !ok {
		log.Fatal("Could not find LINODE_TOKEN, please assert it is set.")
	}
	tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey})

	oauth2Client := &http.Client{
		Transport: &oauth2.Transport{
			Source: tokenSource,
		},
	}

	linodeClient := linodego.NewClient(oauth2Client)
	linodeClient.SetDebug(true)

	opts := linodego.ListOptions{PageOptions: &linodego.PageOptions{Page: 2}, PageSize: 500}
	res, err := linodeClient.ListVolumes(context.Background(), &opts)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v", res)
}

PageSize is on ListOptions instead of PageOptions because PageOptions appears to be structured to be deserialized from every request, and page size is not echoed back by the api server.

Copy link
Contributor

@0xch4z 0xch4z left a comment

Choose a reason for hiding this comment

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

LGTM

@phillc phillc merged commit 8964d97 into linode:master Aug 27, 2020
LBGarber pushed a commit to LBGarber/linodego that referenced this pull request Mar 15, 2021
lgarber-akamai pushed a commit to lgarber-akamai/linodego that referenced this pull request Feb 13, 2023
Implements PageSize to requests
lgarber-akamai pushed a commit to lgarber-akamai/linodego that referenced this pull request Feb 13, 2023
Implements PageSize to requests
lgarber-akamai pushed a commit to lgarber-akamai/linodego that referenced this pull request Feb 13, 2023
Implements PageSize to requests
lgarber-akamai pushed a commit to lgarber-akamai/linodego that referenced this pull request Feb 14, 2023
Implements PageSize to requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants