Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from trotman23/master
Browse files Browse the repository at this point in the history
Add TLSClientConfig to default http client
  • Loading branch information
paultyng authored Jun 13, 2017
2 parents 5fbf16b + 7c5c379 commit bc2e8dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"crypto/tls"
"fmt"

"github.com/tomnomnom/linkheader"
Expand Down Expand Up @@ -32,9 +33,10 @@ type ErrorDetail struct {

// Config contains all the configuration data for the API Client
type Config struct {
APIKey string
BaseURL string
Debug bool
APIKey string
BaseURL string
Debug bool
TLSConfig *tls.Config
}

// New returns a new Client for the specified apiKey.
Expand All @@ -49,6 +51,9 @@ func New(config Config) Client {
r.SetHeader("X-Api-Key", config.APIKey)
r.SetHostURL(baseURL)

if config.TLSConfig != nil {
r.SetTLSClientConfig(config.TLSConfig)
}
if config.Debug {
r.SetDebug(true)
}
Expand Down
17 changes: 17 additions & 0 deletions api/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"crypto/tls"
"net/http"
"net/http/httptest"
)
Expand All @@ -16,3 +17,19 @@ func newTestAPIClient(handler http.Handler) *Client {

return &c
}

func newTestAPIClientTLSConfig(handler http.Handler) *Client {
ts := httptest.NewServer(handler)

tlsCfg := &tls.Config{}
tlsCfg.InsecureSkipVerify = true

c := New(Config{
APIKey: "123456",
BaseURL: ts.URL,
Debug: false,
TLSConfig: tlsCfg,
})

return &c
}

0 comments on commit bc2e8dd

Please sign in to comment.