Skip to content

Commit

Permalink
Enable gosimple linter, fix issues
Browse files Browse the repository at this point in the history
gosimple is a Go linter that specializes in simplifying code

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
  • Loading branch information
siggy committed Feb 23, 2019
1 parent 43d29d6 commit d700d33
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ linters:
disable:
- deadcode
- errcheck
- gosimple
- staticcheck
- structcheck
- unused
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func renderEndpoints(endpoints *pb.EndpointsResponse, options *endpointsOptions)
writeEndpointsToBuffer(endpoints, w, options)
w.Flush()

return string(buffer.Bytes())
return buffer.String()
}

type rowEndpoint struct {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func renderStats(buffer bytes.Buffer, options *statOptionsBase) string {
var out string
switch options.outputFormat {
case "json":
out = string(buffer.Bytes())
out = buffer.String()
default:
// strip left padding on the first column
out = string(buffer.Bytes()[padding:])
Expand Down
4 changes: 1 addition & 3 deletions controller/k8s/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ func newAPI(resourceConfigs []string, extraConfigs ...string) (*API, []runtime.O
k8sResults = append(k8sResults, obj)
}

for _, config := range extraConfigs {
k8sConfigs = append(k8sConfigs, config)
}
k8sConfigs = append(k8sConfigs, extraConfigs...)

api, err := NewFakeAPI("", k8sConfigs...)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions controller/proxy-injector/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package injector

import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestNewWebhookServer(t *testing.T) {
t.Fatal("Unexpected error: ", err)
}

if server.Addr != fmt.Sprintf("%s", addr) {
if server.Addr != addr {
t.Errorf("Expected server address to be :%q", addr)
}
}
2 changes: 1 addition & 1 deletion testutil/kubernetes_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (h *KubernetesHelper) GetPodsForDeployment(namespace string, deploymentName
// that's in the format namespace/resource. If the strings is in a different
// format it returns an error.
func (h *KubernetesHelper) ParseNamespacedResource(resource string) (string, string, error) {
r := regexp.MustCompile("^(.+)\\/(.+)$")
r := regexp.MustCompile(`^(.+)\/(.+)$`)
matches := r.FindAllStringSubmatch(resource, 2)
if len(matches) == 0 {
return "", "", fmt.Errorf("string [%s] didn't contain expected format for namespace/resource, extracted: %v", resource, matches)
Expand Down
2 changes: 1 addition & 1 deletion web/srv/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (h *handler) handleAPITap(w http.ResponseWriter, req *http.Request, p httpr
break
}

if err := ws.WriteMessage(websocket.TextMessage, []byte(buf.String())); err != nil {
if err := ws.WriteMessage(websocket.TextMessage, buf.Bytes()); err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseNormalClosure) {
log.Error(err)
}
Expand Down

0 comments on commit d700d33

Please sign in to comment.