Skip to content

Commit

Permalink
Improve the http client.
Browse files Browse the repository at this point in the history
  • Loading branch information
srdjanrocket committed Mar 2, 2018
1 parent ea7d8a7 commit a65dc76
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package hypertrack
import (
"encoding/json"
"fmt"
"net"
"net/http"
"time"
)

const PROTOCOL = "https"
const HOST = "api.hypertrack.com"
const VERSION = "v1"
const TIMEOUT = 10
const IDLECONNECTIONTIMEOUT = 60
const MAXIDLECONNECTIONS = 100
const TIMEOUT = 30

/*
Client to the HTTP API of Hypertrack.
Expand All @@ -29,9 +28,18 @@ There easiest way to configure the library is by creating a new `Hypertrack` ins
*/
func NewClient(key, secret string) *Client {
tr := &http.Transport{
MaxIdleConns: MAXIDLECONNECTIONS,
MaxIdleConnsPerHost: MAXIDLECONNECTIONS,
IdleConnTimeout: time.Second * IDLECONNECTIONTIMEOUT,
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: TIMEOUT * time.Second,
KeepAlive: TIMEOUT * time.Second,
DualStack: true,
}).DialContext,
TLSHandshakeTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100,
IdleConnTimeout: time.Second * 60,
}
client := &http.Client{
Transport: tr,
Expand Down

0 comments on commit a65dc76

Please sign in to comment.