-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
I think resend package could define an interface for http client so it will be easier handle rate limit.
example:
package resend
type HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}
// Client handles communication with Resend API.
type Client struct {
// HTTP client
// proposal:
client HTTPClient
// current:
// client *http.Client
// Api Key
ApiKey string
// .....
}
func NewCustomClient(httpClient HTTPClient, apiKey string) *Client {
...
}This makes it easier for each developer to handle rate limiting using the strategy that best fits their needs, while exposing only the required client method: .Do(req) (*res, error)
This way, I can plug in my own rate limiter via an interface instead of relying on a concrete pointer implementation.
example:
package impl
import (
"net/http"
"github.com/resend/resend-go"
ratelimit "github.com/mtavano/devkito/clients/http"
)
func NewMailer(apiKey string, maxReq, windowSeconds int) *resend.Client {
httpClient := ratelimit.NewClient(http.Options{
MaxRequest: 2,
WindowInSeconds: 1,
}, http.DefaultClient)
return resend.NewCustomClient(httpClient, apiKet)
}I would like to help submitting the PR but havent seen any contribution guide.
That said, I’ll probably implement this in a fork anyway, since I don’t see an elegant way to achieve this without wrapping the entire package.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels