Skip to content

Commit

Permalink
Fix some warnings/errors reported by gometalinter
Browse files Browse the repository at this point in the history
I'm not going to enable gometalinter yet, but this is a good initial
step.

Most of the failures where reported by goconst and aligncheck.
  • Loading branch information
fsouza committed Sep 18, 2016
1 parent 9a83e57 commit 6b15042
Show file tree
Hide file tree
Showing 26 changed files with 384 additions and 391 deletions.
3 changes: 2 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *Client) AuthCheck(conf *AuthConfiguration) (AuthStatus, error) {
if conf == nil {
return authStatus, fmt.Errorf("conf is nil")
}
resp, err := c.do("POST", "/auth", doOptions{data: conf})
resp, err := c.do(http.MethodPost, "/auth", doOptions{data: conf})
if err != nil {
return authStatus, err
}
Expand Down
16 changes: 7 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (c *Client) Endpoint() string {
// See https://goo.gl/kQCfJj for more details.
func (c *Client) Ping() error {
path := "/_ping"
resp, err := c.do("GET", path, doOptions{})
resp, err := c.do(http.MethodGet, path, doOptions{})
if err != nil {
return err
}
Expand All @@ -375,7 +375,7 @@ func (c *Client) Ping() error {
}

func (c *Client) getServerAPIVersionString() (version string, err error) {
resp, err := c.do("GET", "/version", doOptions{})
resp, err := c.do(http.MethodGet, "/version", doOptions{})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -432,7 +432,7 @@ func (c *Client) do(method, path string, doOptions doOptions) (*http.Response, e
req.Header.Set("User-Agent", userAgent)
if doOptions.data != nil {
req.Header.Set("Content-Type", "application/json")
} else if method == "POST" {
} else if method == http.MethodPost {
req.Header.Set("Content-Type", "plain/text")
}

Expand Down Expand Up @@ -486,7 +486,7 @@ func chooseError(ctx context.Context, err error) error {
}

func (c *Client) stream(method, path string, streamOptions streamOptions) error {
if (method == "POST" || method == "PUT") && streamOptions.in == nil {
if (method == http.MethodPost || method == "PUT") && streamOptions.in == nil {
streamOptions.in = bytes.NewReader(nil)
}
if path != "/version" && !c.SkipServerVersionCheck && c.expectedAPIVersion == nil {
Expand All @@ -500,7 +500,7 @@ func (c *Client) stream(method, path string, streamOptions streamOptions) error
return err
}
req.Header.Set("User-Agent", userAgent)
if method == "POST" {
if method == http.MethodPost {
req.Header.Set("Content-Type", "plain/text")
}
for key, val := range streamOptions.headers {
Expand Down Expand Up @@ -530,10 +530,8 @@ func (c *Client) stream(method, path string, streamOptions streamOptions) error
return err
}
go func() {
select {
case <-subCtx.Done():
dial.Close()
}
<-subCtx.Done()
dial.Close()
}()
breader := bufio.NewReader(dial)
err = req.Write(dial)
Expand Down
28 changes: 12 additions & 16 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestNewTSLAPIClientUnixEndpoint(t *testing.T) {
if client.endpoint != endpoint {
t.Errorf("Expected endpoint %s. Got %s.", endpoint, client.endpoint)
}
rsp, err := client.do("GET", "/", doOptions{})
rsp, err := client.do(http.MethodGet, "/", doOptions{})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestClientStreamTimeoutNotHit(t *testing.T) {
t.Fatal(err)
}
var w bytes.Buffer
err = client.stream("POST", "/image/create", streamOptions{
err = client.stream(http.MethodPost, "/image/create", streamOptions{
setRawTerminal: true,
stdout: &w,
inactivityTimeout: 300 * time.Millisecond,
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestClientStreamInactivityTimeout(t *testing.T) {
t.Fatal(err)
}
var w bytes.Buffer
err = client.stream("POST", "/image/create", streamOptions{
err = client.stream(http.MethodPost, "/image/create", streamOptions{
setRawTerminal: true,
stdout: &w,
inactivityTimeout: 100 * time.Millisecond,
Expand Down Expand Up @@ -539,7 +539,7 @@ func TestClientStreamContextDeadline(t *testing.T) {
var w bytes.Buffer
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
err = client.stream("POST", "/image/create", streamOptions{
err = client.stream(http.MethodPost, "/image/create", streamOptions{
setRawTerminal: true,
stdout: &w,
context: ctx,
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestClientStreamContextCancel(t *testing.T) {
time.Sleep(200 * time.Millisecond)
cancel()
}()
err = client.stream("POST", "/image/create", streamOptions{
err = client.stream(http.MethodPost, "/image/create", streamOptions{
setRawTerminal: true,
stdout: &w,
context: ctx,
Expand All @@ -601,7 +601,7 @@ func TestClientDoContextDeadline(t *testing.T) {
}
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
_, err = client.do("POST", "/image/create", doOptions{
_, err = client.do(http.MethodPost, "/image/create", doOptions{
context: ctx,
})
if err != context.DeadlineExceeded {
Expand All @@ -622,7 +622,7 @@ func TestClientDoContextCancel(t *testing.T) {
time.Sleep(100 * time.Millisecond)
cancel()
}()
_, err = client.do("POST", "/image/create", doOptions{
_, err = client.do(http.MethodPost, "/image/create", doOptions{
context: ctx,
})
if err != context.Canceled {
Expand Down Expand Up @@ -651,7 +651,7 @@ func TestClientStreamTimeoutUnixSocket(t *testing.T) {
t.Fatal(err)
}
var w bytes.Buffer
err = client.stream("POST", "/image/create", streamOptions{
err = client.stream(http.MethodPost, "/image/create", streamOptions{
setRawTerminal: true,
stdout: &w,
inactivityTimeout: 100 * time.Millisecond,
Expand Down Expand Up @@ -733,17 +733,17 @@ func TestClientDoConcurrentStress(t *testing.T) {
waiters := make(chan CloseWaiter, n)
for i := 0; i < n; i++ {
path := fmt.Sprintf("/%05d", i)
paths = append(paths, "GET"+path)
paths = append(paths, "POST"+path)
paths = append(paths, http.MethodGet+path)
paths = append(paths, http.MethodPost+path)
paths = append(paths, "HEAD"+path)
wg.Add(1)
go func() {
defer wg.Done()
_, clientErr := client.do("GET", path, doOptions{})
_, clientErr := client.do(http.MethodGet, path, doOptions{})
if clientErr != nil {
errsCh <- clientErr
}
clientErr = client.stream("POST", path, streamOptions{})
clientErr = client.stream(http.MethodPost, path, streamOptions{})
if clientErr != nil {
errsCh <- clientErr
}
Expand Down Expand Up @@ -832,7 +832,3 @@ type dumb struct {
Z int `qs:"zee"`
Person *person `qs:"p"`
}

type fakeEndpointURL struct {
Scheme string
}
Loading

0 comments on commit 6b15042

Please sign in to comment.