forked from resend/archived-resend-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresend.go
executable file
·93 lines (76 loc) · 1.85 KB
/
resend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package resend
import (
"github.com/resendlabs/resend-go/pkg/models/shared"
"github.com/resendlabs/resend-go/pkg/utils"
"net/http"
"time"
)
var ServerList = []string{
"https://api.resend.com",
}
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
type Resend struct {
Email *email
// Non-idiomatic field names below are to namespace fields from the fields names above to avoid name conflicts
_defaultClient HTTPClient
_securityClient HTTPClient
_security *shared.Security
_serverURL string
_language string
_sdkVersion string
_genVersion string
}
type SDKOption func(*Resend)
func WithServerURL(serverURL string, params map[string]string) SDKOption {
return func(sdk *Resend) {
if params != nil {
serverURL = utils.ReplaceParameters(serverURL, params)
}
sdk._serverURL = serverURL
}
}
func WithClient(client HTTPClient) SDKOption {
return func(sdk *Resend) {
sdk._defaultClient = client
}
}
func WithSecurity(security shared.Security) SDKOption {
return func(sdk *Resend) {
sdk._security = &security
}
}
func New(opts ...SDKOption) *Resend {
sdk := &Resend{
_language: "go",
_sdkVersion: "1.2.1",
_genVersion: "1.5.3",
}
for _, opt := range opts {
opt(sdk)
}
// Use WithClient to override the default client if you would like to customize the timeout
if sdk._defaultClient == nil {
sdk._defaultClient = &http.Client{Timeout: 60 * time.Second}
}
if sdk._securityClient == nil {
if sdk._security != nil {
sdk._securityClient = utils.ConfigureSecurityClient(sdk._defaultClient, sdk._security)
} else {
sdk._securityClient = sdk._defaultClient
}
}
if sdk._serverURL == "" {
sdk._serverURL = ServerList[0]
}
sdk.Email = newEmail(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
return sdk
}