From 165b2fb17042e6609c9bdcfd18b3b1e173f99a00 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Tue, 5 Mar 2019 11:02:40 +0100 Subject: [PATCH] Add a Makefile and go.mod file This adds a Makefile and go.mod/go.sum files with library dependencies. I've also updated some code failing on linting. --- .travis.yml | 21 +++++++++++++-------- Makefile | 15 +++++++++++++++ dcos/client.go | 2 +- dcos/httpclient.go | 29 +++++++++++++++++------------ go.mod | 11 +++++++++++ go.sum | 19 +++++++++++++++++++ 6 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 Makefile create mode 100644 go.mod create mode 100644 go.sum diff --git a/.travis.yml b/.travis.yml index 5cf2ffe..d76f3a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9534855 --- /dev/null +++ b/Makefile @@ -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 .)" diff --git a/dcos/client.go b/dcos/client.go index dcd5ecd..83d699a 100644 --- a/dcos/client.go +++ b/dcos/client.go @@ -5,7 +5,7 @@ import ( "net/http" ) -// Client +// Client is a client for DC/OS. type Client struct { HTTPClient *http.Client Config *Config diff --git a/dcos/httpclient.go b/dcos/httpclient.go index f29a90c..2184a69 100644 --- a/dcos/httpclient.go +++ b/dcos/httpclient.go @@ -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 @@ -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 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c28093b --- /dev/null +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8fe55e5 --- /dev/null +++ b/go.sum @@ -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=