@@ -6,13 +6,15 @@ import (
6
6
"net/http"
7
7
"net/url"
8
8
"runtime"
9
+ "time"
9
10
10
11
"github.com/socketlabs/socketlabs-go/injectionapi/core"
11
12
"github.com/socketlabs/socketlabs-go/injectionapi/core/serialization"
12
13
"github.com/socketlabs/socketlabs-go/injectionapi/message"
13
14
)
14
15
15
16
const endpointURL = "https://inject.socketlabs.com/api/v1/email"
17
+ const requestTimeout = 120
16
18
17
19
// ISocketlabsClient is used to easily send messages through the Socketlabs Injection API
18
20
type ISocketlabsClient interface {
@@ -29,8 +31,14 @@ type ISocketlabsClient interface {
29
31
// SetProxyUrl sets the proxy url.
30
32
SetProxyURL (proxyURL string )
31
33
34
+ // SetRequestTimeout sets the timeout.
35
+ SetRequestTimeout (timeout int )
36
+
32
37
// GetEndpointURL retreives the API endpoint.
33
38
GetEndpointURL () string
39
+
40
+ // GetRequestTimeout retreives the timeout.
41
+ GetRequestTimeout () int
34
42
}
35
43
36
44
// socketlabsClient is the default ISocketlabsClient implementation
@@ -39,6 +47,7 @@ type socketlabsClient struct {
39
47
APIKey string
40
48
EndpointURL string
41
49
ProxyURL string
50
+ RequestTimeout int
42
51
}
43
52
44
53
// CreateClient instatiates new client using the specified credentials
@@ -47,6 +56,7 @@ func CreateClient(serverID int, apiKey string) ISocketlabsClient {
47
56
ServerID : serverID ,
48
57
APIKey : apiKey ,
49
58
EndpointURL : endpointURL ,
59
+ RequestTimeout : requestTimeout ,
50
60
}
51
61
}
52
62
@@ -57,6 +67,7 @@ func CreateClientWithProxy(serverID int, apiKey string, proxyURL string) ISocket
57
67
APIKey : apiKey ,
58
68
EndpointURL : endpointURL ,
59
69
ProxyURL : proxyURL ,
70
+ RequestTimeout : requestTimeout ,
60
71
}
61
72
}
62
73
@@ -70,11 +81,21 @@ func (socketlabsClient *socketlabsClient) SetProxyURL(proxyURL string) {
70
81
socketlabsClient .ProxyURL = proxyURL
71
82
}
72
83
84
+ // SetRequestTimeout sets the timeout
85
+ func (socketlabsClient * socketlabsClient ) SetRequestTimeout (timeout int ) {
86
+ socketlabsClient .RequestTimeout = timeout
87
+ }
88
+
73
89
// GetEndpointURL retreives the API endpoint.
74
90
func (socketlabsClient * socketlabsClient ) GetEndpointURL () string {
75
91
return socketlabsClient .EndpointURL
76
92
}
77
93
94
+ // GetRequestTimeout retreives the timeout
95
+ func (socketlabsClient * socketlabsClient ) GetRequestTimeout () int {
96
+ return socketlabsClient .RequestTimeout
97
+ }
98
+
78
99
// SendBasic sends a basic email message and returns the response from the Injection API.
79
100
func (socketlabsClient * socketlabsClient ) SendBasic (message * message.BasicMessage ) (SendResponse , error ) {
80
101
@@ -185,7 +206,11 @@ func (socketlabsClient *socketlabsClient) createHttpClient(proxyUrl string) (*ht
185
206
return nil , err
186
207
}
187
208
209
+ //converting timeout from int to time
210
+ var timeout time.Duration
211
+ timeout = time .Duration (socketlabsClient .RequestTimeout ) * time .Second
212
+
188
213
//create client with proxy url
189
- client := & http.Client {Transport : & http.Transport {Proxy : http .ProxyURL (proxyURL )}}
214
+ client := & http.Client {Transport : & http.Transport {Proxy : http .ProxyURL (proxyURL )}, Timeout : timeout }
190
215
return client , nil
191
216
}
0 commit comments