-
Notifications
You must be signed in to change notification settings - Fork 779
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
Options #1299
Merged
Merged
Options #1299
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add functional options to request, RequestWithBucketID, RequestWithLockedBucket. These options allow for request modification and overriding REST related Session fields, such as Client, MaxRestRetries and ShouldRetryOnRateLimit.
Implement WithContext and WithMaxRestRetries options.
Add documentation to the options
FedorLap2006
added
feature
Feature implementation
feedback
Additional feedback is required
high priority
Issue or PR with high priority of merge
rest
REST API related issues and pull requests
labels
Dec 15, 2022
Add option arguments to all Session methods.
Rename requestConfig to newRequestConfig to match other constructor functions naming.
Manually revert the formatting of documentation in certain functions.
Add description for fetchOptions parameter of Session.UserChannelPermissions.
FedorLap2006
commented
Jan 15, 2023
Pass options to ChannelMessageSendEmbedsReply call in ChannelMessageSendEmbedReply
This was
linked to
issues
Jan 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature
Feature implementation
feedback
Additional feedback is required
high priority
Issue or PR with high priority of merge
rest
REST API related issues and pull requests
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since the beginning, DiscordGo did not have ability for adding per-call customization:
ChannelMessageDelete
, instead handling the error by yourself?GuildBanCreate
, likeX-Audit-Log-Reason
, to comment your action in audit log?We’ve been thinking on how to combat this problem, and came up with the following solutions:
Builders pattern
Functional options
This PR implements the latter. It provides a few pre-built options. However, you can always supply your custom option.
Options have access to a
RequestConfig
struct, which is internally used byRequestX
functions. This config allows you to modify a few global settings, likeClient
,ShouldRetryOnRateLimit
andMaxRestRetries
, but it also allows you to modify the request directly.A typical functional option would look like this:
These are built-in options discordgo will provide:
WithClient
- Controlhttp.Client
used for the request (defaults tos.Client
)WithHeader
- Change a certain header in the requestWithAuditLogReason
- SetX-Audit-Log-Reason
headerWithLocale
- SetX-Discord-Locale
headerWithRetryOnRateLimit
- ControlSession.ShouldRetryOnRateLimit
field for the requestWithMaxRestRetries
- ControlSession.MaxRestRetries
field for the requestWithContext
- Provide acontext.Context
to thehttp.Request
This change will be affecting all of the REST endpoints. However it should be non-breaking.
If you have used any function signatures though, you would need to change them accordingly:
Special thanks to @jalavosus for bringing up the issue with context in REST functions. His PR (#1119) was one of the factors that inspired me to implement this functionality.