Use cleanhttp for new http clients
This commit is contained in:
parent
5a704ec14d
commit
1373a6086b
|
@ -3,9 +3,9 @@ package aws
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
@ -101,7 +101,7 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
Region: aws.String(c.Region),
|
Region: aws.String(c.Region),
|
||||||
MaxRetries: aws.Int(c.MaxRetries),
|
MaxRetries: aws.Int(c.MaxRetries),
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: cleanhttp.DefaultClient(),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("[INFO] Initializing IAM Connection")
|
log.Println("[INFO] Initializing IAM Connection")
|
||||||
|
@ -127,7 +127,7 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
Region: aws.String("us-east-1"),
|
Region: aws.String("us-east-1"),
|
||||||
MaxRetries: aws.Int(c.MaxRetries),
|
MaxRetries: aws.Int(c.MaxRetries),
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: cleanhttp.DefaultClient(),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("[INFO] Initializing DynamoDB connection")
|
log.Println("[INFO] Initializing DynamoDB connection")
|
||||||
|
|
|
@ -3,8 +3,8 @@ package dme
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/soniah/dnsmadeeasy"
|
"github.com/soniah/dnsmadeeasy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func (c *Config) Client() (*dnsmadeeasy.Client, error) {
|
||||||
return nil, fmt.Errorf("Error setting up client: %s", err)
|
return nil, fmt.Errorf("Error setting up client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.HTTP = &http.Client{}
|
client.HTTP = cleanhttp.DefaultClient()
|
||||||
|
|
||||||
if c.UseSandbox {
|
if c.UseSandbox {
|
||||||
client.URL = dnsmadeeasy.SandboxURL
|
client.URL = dnsmadeeasy.SandboxURL
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package packet
|
package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
|
|
||||||
"github.com/packethost/packngo"
|
"github.com/packethost/packngo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,5 +15,5 @@ type Config struct {
|
||||||
|
|
||||||
// Client() returns a new client for accessing packet.
|
// Client() returns a new client for accessing packet.
|
||||||
func (c *Config) Client() *packngo.Client {
|
func (c *Config) Client() *packngo.Client {
|
||||||
return packngo.NewClient(consumerToken, c.AuthToken, &http.Client{})
|
return packngo.NewClient(consumerToken, c.AuthToken, cleanhttp.DefaultClient())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -83,7 +85,7 @@ func (c *AtlasClient) Get() (*Payload, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request the url
|
// Request the url
|
||||||
client := &http.Client{}
|
client := cleanhttp.DefaultClient()
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -162,7 +164,7 @@ func (c *AtlasClient) Put(state []byte) error {
|
||||||
req.ContentLength = int64(len(state))
|
req.ContentLength = int64(len(state))
|
||||||
|
|
||||||
// Make the request
|
// Make the request
|
||||||
client := &http.Client{}
|
client := cleanhttp.DefaultClient()
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to upload state: %v", err)
|
return fmt.Errorf("Failed to upload state: %v", err)
|
||||||
|
@ -188,7 +190,7 @@ func (c *AtlasClient) Delete() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the request
|
// Make the request
|
||||||
client := &http.Client{}
|
client := cleanhttp.DefaultClient()
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to delete state: %v", err)
|
return fmt.Errorf("Failed to delete state: %v", err)
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
etcdapi "github.com/coreos/etcd/client"
|
etcdapi "github.com/coreos/etcd/client"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func etcdFactory(conf map[string]string) (Client, error) {
|
func etcdFactory(conf map[string]string) (Client, error) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPClient_impl(t *testing.T) {
|
func TestHTTPClient_impl(t *testing.T) {
|
||||||
|
@ -24,7 +26,7 @@ func TestHTTPClient(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &HTTPClient{URL: url, Client: &http.Client{}}
|
client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()}
|
||||||
testClient(t, client)
|
testClient(t, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -14,6 +13,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
|
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func s3Factory(conf map[string]string) (Client, error) {
|
func s3Factory(conf map[string]string) (Client, error) {
|
||||||
|
@ -76,7 +76,7 @@ func s3Factory(conf map[string]string) (Client, error) {
|
||||||
awsConfig := &aws.Config{
|
awsConfig := &aws.Config{
|
||||||
Credentials: credentialsProvider,
|
Credentials: credentialsProvider,
|
||||||
Region: aws.String(regionName),
|
Region: aws.String(regionName),
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: cleanhttp.DefaultClient(),
|
||||||
}
|
}
|
||||||
nativeClient := s3.New(awsConfig)
|
nativeClient := s3.New(awsConfig)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue