Skip to content

Commit a194ff2

Browse files
authored
Merge pull request #33 from romanyx/feautue/http_client_timeout
Set Timeout for http.Client
2 parents a951423 + beadae6 commit a194ff2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net/url"
2121
"runtime"
2222
"strings"
23+
"time"
2324
)
2425

2526
const (
@@ -28,6 +29,9 @@ const (
2829

2930
// Endpoint points you to MessageBird REST API.
3031
Endpoint = "https://rest.messagebird.com"
32+
33+
// httpClientTimeout is used to limit http.Client waiting time.
34+
httpClientTimeout = 15 * time.Second
3135
)
3236

3337
const (
@@ -62,8 +66,13 @@ type Client struct {
6266
}
6367

6468
// New creates a new MessageBird client object.
65-
func New(AccessKey string) *Client {
66-
return &Client{AccessKey: AccessKey, HTTPClient: &http.Client{}}
69+
func New(accessKey string) *Client {
70+
return &Client{
71+
AccessKey: accessKey,
72+
HTTPClient: &http.Client{
73+
Timeout: httpClientTimeout,
74+
},
75+
}
6776
}
6877

6978
// Request is for internal use only and unstable.

0 commit comments

Comments
 (0)