Skip to content

Commit

Permalink
Default HTTP client should have timeout (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo authored Nov 23, 2024
1 parent 6e555a9 commit 1c5bd4a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions resend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
)

const (
Expand All @@ -19,6 +20,10 @@ const (

var defaultBaseURL = getEnv("RESEND_BASE_URL", "https://api.resend.com/")

var defaultHTTPClient = &http.Client{
Timeout: time.Minute,
}

// Client handles communication with Resend API.
type Client struct {
// HTTP client
Expand Down Expand Up @@ -48,13 +53,13 @@ type Client struct {
// NewClient is the default client constructor
func NewClient(apiKey string) *Client {
key := strings.Trim(strings.TrimSpace(apiKey), "'")
return NewCustomClient(http.DefaultClient, key)
return NewCustomClient(defaultHTTPClient, key)
}

// NewCustomClient builds a new Resend API client, using a provided Http client.
func NewCustomClient(httpClient *http.Client, apiKey string) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
httpClient = defaultHTTPClient
}

baseURL, _ := url.Parse(defaultBaseURL)
Expand Down

0 comments on commit 1c5bd4a

Please sign in to comment.