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
Added POC arbitrary query strings #4
Conversation
This gets my vote—some of the defaults (e.g. 20 per page, 50 per page) are quite low and it's preferable to save another HTTP round-trip where possible. You could implement this as a method on API with a warning to not call concurrently/during requests (i.e. The downside to that approach is that some values may not make sense for every endpoint, and passing a |
If we stick with the pattern I've demonstrated in ListWAFRules for the other methods, because it's variadic you don't actually have to pass anything as the third argument. If we make API.makeRequest take the same (that is 0 or more url.Values) it would be more DRY as we can either implement validation (i.e. error on more than one instance passed in) or even simple merging within the API object. |
I'm fine with this PR as-is, but I'm definitely open to making this more DRY, as I'm already doing similar things in dns.go and zone.go (and I'm not entirely happy with the way I'm doing it there). I like the idea of extending the API struct and having a method call to modify it. @oholiab if you like I'll merge this and we can do the other work later, or if you've already got something in mind feel free to push it to this PR for review. Thanks for contributing! |
As long as we merge multiple Added: another option is functional options - e.g. +func (api *API) ListWAFRules(zoneID string, packageID string, opts ...APIOption) ([]WAFRule, error) {
...
type option struct {
perPage int
ascending bool
etc.
}
type APIOption func(option) option
func PerPage(n int) APIOption {
return func(o option) option {
return o.perPage = n
}
}
// Example
api.ListWAFRules("1173813", "200318138", cloudflare.PerPage(100), cloudflare.Ascending()) |
I think maybe hold off on merging actually - I should be able to knock Sound good?
|
That works too. Appreciate the work/effort @oholiab! |
Sounds good to me. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
So there's a strong chance that this particular incarnation of this PR will be rejected, but I figured a POC would be better than trying to say what I mean in an issue
I've modified the ListWAFRules function to take an optional url.Values... My personal use case for this being that I want to see ALL my WAF rules, so ?per_page=1000 for example.
Obviously this is introducing a special case, so a couple of ideas would be:
Equally, I'd be very happy for this to be accepted in to master as it's on my critical path, but beyond that the second option would help immensely for my use case.
Anyway, let me know what you think, I'm happy to do some more leg work on this.