Skip to content

Commit

Permalink
Add a Makefile and go.mod file
Browse files Browse the repository at this point in the history
This adds a Makefile and go.mod/go.sum files with library dependencies.

I've also updated some code failing on linting.
  • Loading branch information
bamarni committed Mar 5, 2019
1 parent 1346326 commit 165b2fb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
sudo: false

language: go

go:
- "1.11.x"
- "1.10.x"
- "1.9.x"
matrix:
fast_finish: true
- "1.12.x"

go_import_path: github.com/dcos/client-go

env:
- GO111MODULE=on

before_install:
- env GO111MODULE=off go get -u golang.org/x/lint/golint

script:
- go get -t -v ./...
- diff -u <(echo -n) <(gofmt -d -s .)
- go tool vet .
- go test -v -race ./...
- make test
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: test
test: vet
go test -race -cover ./...

.PHONY: vet
vet: lint
go vet ./...

.PHONY: lint
lint: fmt
golint -set_exit_status ./...

.PHONY: fmt
fmt:
bash -c "diff -u <(echo -n) <(gofmt -d -s .)"
2 changes: 1 addition & 1 deletion dcos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

// Client
// Client is a client for DC/OS.
type Client struct {
HTTPClient *http.Client
Config *Config
Expand Down
29 changes: 17 additions & 12 deletions dcos/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import (
)

const (
// Set a 10 seconds timeout for the connection to be established.
DefaultHTTPClientDialContextTimeout = 10 * time.Second
// Set it to 10 seconds as well for the TLS handshake when using HTTPS.
DefaultHTTPClientTLSHandshakeTimeout = 10 * time.Second
// The client will be dealing with a single host (the one in baseURL),
// set max idle connections to 30 regardless of the host.
DefaultHTTPClientMaxIdleConns = 30
DefaultHTTPClientMaxIdleConnsPerHost = 30
// defaultTransportDialTimeout specifies the maximum amount of time
// waiting for a connection to be established.
defaultTransportDialTimeout = 10 * time.Second

// defaultTransportTLSHandshakeTimeout specifies the maximum
// amount of time waiting to wait for a TLS handshake.
defaultTransportTLSHandshakeTimeout = 10 * time.Second

// defaultTransportMaxIdleConns specifies the maximum number of idle connections.
defaultTransportMaxIdleConns = 30
)

// DefaultTransport is a http.RoundTripper that adds authentication based on Config
Expand Down Expand Up @@ -66,17 +68,20 @@ func NewHTTPClient(config *Config) (*http.Client, error) {
Proxy: http.ProxyFromEnvironment,

DialContext: (&net.Dialer{
Timeout: DefaultHTTPClientDialContextTimeout,
Timeout: defaultTransportDialTimeout,
}).DialContext,

TLSHandshakeTimeout: DefaultHTTPClientTLSHandshakeTimeout,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.TLS().Insecure,
RootCAs: config.TLS().RootCAs,
},

MaxIdleConns: DefaultHTTPClientMaxIdleConns,
MaxIdleConnsPerHost: DefaultHTTPClientMaxIdleConnsPerHost,
TLSHandshakeTimeout: defaultTransportTLSHandshakeTimeout,

// As the client is dealing with a single host (the DC/OS master node),
// set both MaxIdleConns and MaxIdleConnsPerHost to the same value.
MaxIdleConns: defaultTransportMaxIdleConns,
MaxIdleConnsPerHost: defaultTransportMaxIdleConns,
}

return AddTransportHTTPClient(client, config), nil
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/dcos/client-go

go 1.11

require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pelletier/go-toml v1.2.0
github.com/spf13/afero v1.2.1
github.com/spf13/cast v1.3.0
github.com/stretchr/testify v1.3.0
)
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 comments on commit 165b2fb

Please sign in to comment.