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

use go.einride.tech/aip/pagination to reduce code dup #167

Open
glimchb opened this issue Sep 7, 2023 · 0 comments
Open

use go.einride.tech/aip/pagination to reduce code dup #167

glimchb opened this issue Sep 7, 2023 · 0 comments

Comments

@glimchb
Copy link
Member

glimchb commented Sep 7, 2023

see https://github.com/einride/aip-go/tree/master/pagination

see https://github.com/einride/aip-go/blob/d1496baa45a9dcbb474e8ad99c63387f6ce86c85/README.md#aip-132-standard-method-list

see

const (
maxPageSize = 250
defaultPageSize = 50
)
switch {
case pageSize < 0:
return -1, -1, status.Error(codes.InvalidArgument, "negative PageSize is not allowed")
case pageSize == 0:
size = defaultPageSize
case pageSize > maxPageSize:
size = maxPageSize
default:
size = int(pageSize)
}
// fetch offset from the database using opaque token
offset = 0
if pageToken != "" {
var ok bool
offset, ok = pagination[pageToken]
if !ok {
return -1, -1, status.Errorf(codes.NotFound, "unable to find pagination token %s", pageToken)
}
log.Printf("Found offset %d from pagination token: %s", offset, pageToken)
}

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

No branches or pull requests

1 participant