Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
EUREKA_ADDR: http://localhost:${{ job.services.eureka.ports[8761] }}/eureka
run: go test -v -race -coverprofile=coverage.coverprofile -covermode=atomic -tags integration ./...

- name: Run linter
uses: actions-contrib/golangci-lint@v1

- name: Upload coverage
uses: codecov/codecov-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ examples/stringsvc1/stringsvc1
examples/stringsvc2/stringsvc2
examples/stringsvc3/stringsvc3
*.coverprofile
golangci-lint

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
Expand Down Expand Up @@ -42,4 +43,3 @@ Session.vim
*~
# auto-generated tag files
tags

30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
skip-dirs:
- (^|/)pb($|/)
- (^|/)thrift($|/)

timeout: 2m

linters-settings:
golint:
min-confidence: 0.9
goimports:
local-prefixes: github.com/go-kit/kit

linters:
disable-all: true
enable:
- govet
- golint
- gofmt
- staticcheck

issues:
exclude-rules:
- path: _test\.go
text: "should not use basic type string as key in context.WithValue"
linters:
- golint

service:
golangci-lint-version: 1.23.x
6 changes: 3 additions & 3 deletions auth/jwt/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestJWTParser(t *testing.T) {
// Test for malformed token error response
parser = NewParser(keys, method, StandardClaimsFactory)(e)
ctx = context.WithValue(context.Background(), JWTTokenContextKey, malformedKey)
ctx1, err = parser(ctx, struct{}{})
_, err = parser(ctx, struct{}{})
if want, have := ErrTokenMalformed, err; want != have {
t.Fatalf("Expected %+v, got %+v", want, have)
}
Expand All @@ -149,7 +149,7 @@ func TestJWTParser(t *testing.T) {
t.Fatalf("Unable to Sign Token: %+v", err)
}
ctx = context.WithValue(context.Background(), JWTTokenContextKey, token)
ctx1, err = parser(ctx, struct{}{})
_, err = parser(ctx, struct{}{})
if want, have := ErrTokenExpired, err; want != have {
t.Fatalf("Expected %+v, got %+v", want, have)
}
Expand All @@ -162,7 +162,7 @@ func TestJWTParser(t *testing.T) {
t.Fatalf("Unable to Sign Token: %+v", err)
}
ctx = context.WithValue(context.Background(), JWTTokenContextKey, token)
ctx1, err = parser(ctx, struct{}{})
_, err = parser(ctx, struct{}{})
if want, have := ErrTokenNotActive, err; want != have {
t.Fatalf("Expected %+v, got %+v", want, have)
}
Expand Down
26 changes: 9 additions & 17 deletions lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ set -o errexit
set -o nounset
set -o pipefail

if [ ! $(command -v gometalinter) ]
if [ $(command -v golangci-lint) ]
then
go get github.com/alecthomas/gometalinter
gometalinter --update --install
golangci-lint run
exit $?
fi

time gometalinter \
--exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \
--exclude='/thrift/' \
--exclude='/pb/' \
--exclude='no args in Log call \(vet\)' \
--disable=dupl \
--disable=aligncheck \
--disable=gotype \
--cyclo-over=20 \
--tests \
--concurrency=2 \
--deadline=300s \
./...
if [ ! -x ./golangci-lint ]
then
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $PWD
fi

./golangci-lint run
10 changes: 5 additions & 5 deletions log/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func TestStdLibAdapterExtraction(t *testing.T) {
logger := NewLogfmtLogger(buf)
writer := NewStdlibAdapter(logger)
for input, want := range map[string]string{
"hello": "msg=hello\n",
"2009/01/23: hello": "ts=2009/01/23 msg=hello\n",
"2009/01/23 01:23:23: hello": "ts=\"2009/01/23 01:23:23\" msg=hello\n",
"01:23:23: hello": "ts=01:23:23 msg=hello\n",
"2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n",
"hello": "msg=hello\n",
"2009/01/23: hello": "ts=2009/01/23 msg=hello\n",
"2009/01/23 01:23:23: hello": "ts=\"2009/01/23 01:23:23\" msg=hello\n",
"01:23:23: hello": "ts=01:23:23 msg=hello\n",
"2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n",
"2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=hello\n",
"01:23:23.123123 /a/b/c/d.go:23: hello": "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=hello\n",
"2009/01/23 01:23:23 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=hello\n",
Expand Down
4 changes: 2 additions & 2 deletions metrics/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type CloudWatch struct {

type option func(*CloudWatch)

func (s *CloudWatch) apply(opt option) {
func (cw *CloudWatch) apply(opt option) {
if opt != nil {
opt(s)
opt(cw)
}
}

Expand Down
2 changes: 1 addition & 1 deletion metrics/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ LabelValues:
}
}
}
return fmt.Errorf("could not find dimension with name %s and value %s", name, value)
return fmt.Errorf("could not find dimension with name %s and value %s", name, value) // nolint: staticcheck
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion metrics/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (h *Histogram) LabelValues() []string {
func (h *Histogram) Print(w io.Writer) {
h.h.RLock()
defer h.h.RUnlock()
fmt.Fprintf(w, h.h.String())
fmt.Fprint(w, h.h.String())
}

// safeHistogram exists as gohistogram.Histogram is not goroutine-safe.
Expand Down
3 changes: 1 addition & 2 deletions sd/etcd/client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package etcd

import (
"context"
"errors"
"reflect"
"testing"
"time"
"context"

etcd "go.etcd.io/etcd/client"
)
Expand Down Expand Up @@ -135,7 +135,6 @@ func (fw *fakeWatcher) Next(context.Context) (*etcd.Response, error) {
return nil, nil
case <-fw.err:
return nil, errors.New("error from underlying etcd watcher")
default:
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sd/zk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *client) CreateParentNodes(path string) error {
if path[0] != '/' {
return zk.ErrInvalidPath
}
payload := []byte("")
var payload []byte
pathString := ""
pathNodes := strings.Split(path, "/")
for i := 1; i < len(pathNodes); i++ {
Expand Down
6 changes: 3 additions & 3 deletions sd/zk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestNewClient(t *testing.T) {
payload = [][]byte{[]byte("Payload"), []byte("Test")}
)

c, err := NewClient(
_, err := NewClient(
[]string{"FailThisInvalidHost!!!"},
log.NewNopLogger(),
)
Expand All @@ -36,7 +36,7 @@ func TestNewClient(t *testing.T) {
}
}

c, err = NewClient(
c, err := NewClient(
[]string{"localhost"},
log.NewNopLogger(),
ACL(acl),
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestCreateParentNodes(t *testing.T) {
t.Error("expected failed new Instancer")
}

s, err = NewInstancer(c, "invalidpath", log.NewNopLogger())
_, err = NewInstancer(c, "invalidpath", log.NewNopLogger())
if err != stdzk.ErrInvalidPath {
t.Errorf("unexpected error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion tracing/opencensus/endpoint_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type EndpointOptions struct {
// If the function is nil, or the returned name is empty, the existing name for the endpoint is used.
GetName func(ctx context.Context, name string) string

// GetAttributes is an optional function that can extract trace attributes
// GetAttributes is an optional function that can extract trace attributes
// from the context and add them to the span.
GetAttributes func(ctx context.Context) []trace.Attribute
}
Expand Down
7 changes: 4 additions & 3 deletions transport/amqp/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"testing"
"time"

amqptransport "github.com/go-kit/kit/transport/amqp"
"github.com/streadway/amqp"

amqptransport "github.com/go-kit/kit/transport/amqp"
)

var (
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestBadDecode(t *testing.T) {
f: nullFunc,
c: make(chan amqp.Publishing, 1),
deliveries: []amqp.Delivery{
amqp.Delivery{
{
CorrelationId: cid,
},
},
Expand Down Expand Up @@ -157,7 +158,7 @@ func TestSuccessfulPublisher(t *testing.T) {
f: nullFunc,
c: reqChan,
deliveries: []amqp.Delivery{
amqp.Delivery{
{
CorrelationId: cid,
Body: b,
},
Expand Down
6 changes: 3 additions & 3 deletions transport/awslambda/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestInvokeFailDecode(t *testing.T) {
encodeResponse,
HandlerErrorEncoder(func(
ctx context.Context,
err error,
_ error,
) ([]byte, error) {
apigwResp := events.APIGatewayProxyResponse{}
apigwResp.Body = `{"error":"yes"}`
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestInvokeFailEndpoint(t *testing.T) {
}),
HandlerErrorEncoder(func(
ctx context.Context,
err error,
_ error,
) ([]byte, error) {
apigwResp := events.APIGatewayProxyResponse{}
apigwResp.Body = `{"error":"yes"}`
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestInvokeFailEncode(t *testing.T) {
}),
HandlerErrorEncoder(func(
ctx context.Context,
err error,
_ error,
) ([]byte, error) {
// convert error into proper APIGateway response.
apigwResp := events.APIGatewayProxyResponse{}
Expand Down
5 changes: 3 additions & 2 deletions transport/http/proto/proto_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proto

import (
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand All @@ -14,7 +15,7 @@ func TestEncodeProtoRequest(t *testing.T) {

r := httptest.NewRequest(http.MethodGet, "/cat", nil)

err := EncodeProtoRequest(nil, r, cat)
err := EncodeProtoRequest(context.TODO(), r, cat)
if err != nil {
t.Errorf("expected no encoding errors but got: %s", err)
return
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestEncodeProtoResponse(t *testing.T) {

wr := httptest.NewRecorder()

err := EncodeProtoResponse(nil, wr, cat)
err := EncodeProtoResponse(context.TODO(), wr, cat)
if err != nil {
t.Errorf("expected no encoding errors but got: %s", err)
return
Expand Down
6 changes: 3 additions & 3 deletions transport/http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestEncodeJSONResponse(t *testing.T) {

type multiHeaderResponse struct{}

func (_ multiHeaderResponse) Headers() http.Header {
func (multiHeaderResponse) Headers() http.Header {
return http.Header{"Vary": []string{"Origin", "User-Agent"}}
}

Expand All @@ -281,7 +281,7 @@ func TestAddMultipleHeaders(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expect := map[string]map[string]struct{}{"Vary": map[string]struct{}{"Origin": struct{}{}, "User-Agent": struct{}{}}}
expect := map[string]map[string]struct{}{"Vary": {"Origin": {}, "User-Agent": {}}}
for k, vls := range resp.Header {
for _, v := range vls {
delete((expect[k]), v)
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestAddMultipleHeadersErrorEncoder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expect := map[string]map[string]struct{}{"Vary": map[string]struct{}{"Origin": struct{}{}, "User-Agent": struct{}{}}}
expect := map[string]map[string]struct{}{"Vary": {"Origin": {}, "User-Agent": {}}}
for k, vls := range resp.Header {
for _, v := range vls {
delete((expect[k]), v)
Expand Down
1 change: 0 additions & 1 deletion transport/nats/encode_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ type EncodeResponseFunc func(context.Context, string, *nats.Conn, interface{}) e
// endpoints. One straightforward DecodeResponseFunc could be something that
// JSON decodes from the response payload to the concrete response type.
type DecodeResponseFunc func(context.Context, *nats.Msg) (response interface{}, err error)

Loading