This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresend.go
executable file
·103 lines (84 loc) · 2.15 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
94
95
96
97
98
99
100
101
102
103
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)
}
// String provides a helper function to return a pointer to a string
func String(s string) *string { return &s }
// SDK Documentation: Resend is the email platform for developers.
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) SDKOption {
return func(sdk *Resend) {
sdk._serverURL = serverURL
}
}
func WithTemplatedServerURL(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.3.1",
_genVersion: "1.8.2",
}
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
}