Skip to content

update go & golangci-lint #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

indent_size = 8
indent_style = tabs
indent_style = tab
max_line_length = 80

[*.go]
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go: ["1.18", "1.20"]
go: ["1.22", "1.23"]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
Expand All @@ -28,7 +28,7 @@ jobs:
build:
strategy:
matrix:
go: ["1.18", "1.20"]
go: ["1.22", "1.23"]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
Expand All @@ -47,9 +47,9 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.20"
go-version: "1.23"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51
version: v1.61
17 changes: 12 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
linters:
disable-all: true
enable:
- copyloopvar
- errcheck
- exportloopref
- errorlint
- gocritic
- goimports
- godox
- gofumpt
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- nosprintfhostport
- prealloc
- revive
- staticcheck
Expand All @@ -18,8 +22,11 @@ linters:
- unconvert
- unused
- usestdlibvars
- vet

linters-settings:
goimports:
local-prefixes: github.com/simplesurance/grpcconsulresolver
gofumpt:
module-path: github.com/simplesurance/grpcconsulresolver
extra-rules: true
godox:
keywords:
- FIXME
7 changes: 3 additions & 4 deletions consul/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"
"time"

"github.com/hashicorp/consul/api"
consul "github.com/hashicorp/consul/api"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/resolver"
Expand Down Expand Up @@ -66,7 +65,7 @@ func newConsulResolver(

health, err := consulCreateHealthClientFn(&cfg)
if err != nil {
return nil, fmt.Errorf("creating consul client failed. %v", err)
return nil, fmt.Errorf("creating consul client failed: %w", err)
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -133,7 +132,7 @@ func filterPreferOnlyHealthy(entries []*consul.ServiceEntry) []*consul.ServiceEn
healthy := make([]*consul.ServiceEntry, 0, len(entries))

for _, e := range entries {
if e.Checks.AggregatedStatus() == api.HealthPassing {
if e.Checks.AggregatedStatus() == consul.HealthPassing {
healthy = append(healthy, e)
}
}
Expand Down Expand Up @@ -254,7 +253,7 @@ func (c *consulResolver) watcher() {
}
}

func (c *consulResolver) ResolveNow(o resolver.ResolveNowOptions) {
func (c *consulResolver) ResolveNow(resolver.ResolveNowOptions) {
select {
case c.resolveNow <- struct{}{}:

Expand Down
58 changes: 28 additions & 30 deletions consul/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/hashicorp/consul/api"
consul "github.com/hashicorp/consul/api"
"google.golang.org/grpc/resolver"

Expand Down Expand Up @@ -97,13 +96,13 @@ func TestResolve(t *testing.T) {
target: resolver.Target{URL: url.URL{Path: "user-service"}},
consulResponse: []*consul.ServiceEntry{
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "localhost",
Port: 5678,
},
},
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "remotehost",
Port: 1234,
},
Expand Down Expand Up @@ -151,46 +150,46 @@ func TestResolve(t *testing.T) {
target: resolver.Target{URL: url.URL{Path: "credit-service", RawQuery: "health=fallbackToUnhealthy"}},
consulResponse: []*consul.ServiceEntry{
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "localhost",
Port: 5678,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthPassing,
Status: consul.HealthPassing,
},
},
},
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "remotehost",
Port: 9,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthPassing,
Status: consul.HealthPassing,
},
},
},
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "unhealthyHost",
Port: 1234,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthCritical,
Status: consul.HealthCritical,
},
},
},
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "warnedHost",
Port: 1,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthWarning,
Status: consul.HealthWarning,
},
},
},
Expand All @@ -210,24 +209,24 @@ func TestResolve(t *testing.T) {
target: resolver.Target{URL: url.URL{Path: "web-service", RawQuery: "health=fallbackToUnhealthy"}},
consulResponse: []*consul.ServiceEntry{
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "localhost",
Port: 5678,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthCritical,
Status: consul.HealthCritical,
},
},
},
{
Service: &api.AgentService{
Service: &consul.AgentService{
Address: "remotehost",
Port: 1234,
},
Checks: api.HealthChecks{
Checks: consul.HealthChecks{
{
Status: api.HealthCritical,
Status: consul.HealthCritical,
},
},
},
Expand All @@ -245,7 +244,7 @@ func TestResolve(t *testing.T) {

health := mocks.NewConsulHealthClient()
cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand Down Expand Up @@ -284,7 +283,7 @@ func TestResolve(t *testing.T) {
func TestResolveNewAddressOnlyCalledOnChange(t *testing.T) {
health := mocks.NewConsulHealthClient()
cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand Down Expand Up @@ -331,7 +330,7 @@ func TestResolveNewAddressOnlyCalledOnChange(t *testing.T) {
func TestResolveAddrChange(t *testing.T) {
health := mocks.NewConsulHealthClient()
cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand Down Expand Up @@ -420,7 +419,7 @@ func TestResolveAddrChange(t *testing.T) {
func TestResolveAddrChangesToUnresolvable(t *testing.T) {
health := mocks.NewConsulHealthClient()
cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand Down Expand Up @@ -490,7 +489,7 @@ func TestErrorIsReportedOnQueryErrors(t *testing.T) {
health.SetRespError(queryErr)

cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand All @@ -509,11 +508,10 @@ func TestErrorIsReportedOnQueryErrors(t *testing.T) {

for ; err == nil; err = cc.LastReportedError() {
time.Sleep(time.Millisecond)

}

if err != queryErr {
t.Fatalf("resolver error is %+v, expected %+v", err, queryErr)
if !errors.Is(err, queryErr) {
t.Fatalf("resolver error is: '%+v', expected: '%+v'", err, queryErr)
}
}

Expand All @@ -522,7 +520,7 @@ func TestQueryResultsAreSorted(t *testing.T) {
newAddressCallCnt := cc.UpdateStateCallCnt()
health := mocks.NewConsulHealthClient()
cleanup := replaceCreateHealthClientFn(
func(cfg *consul.Config) (consulHealthEndpoint, error) {
func(*consul.Config) (consulHealthEndpoint, error) {
return health, nil
},
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ require (
google.golang.org/protobuf v1.28.1 // indirect
)

go 1.18
go 1.22.8
2 changes: 1 addition & 1 deletion internal/mocks/consulhealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *ConsulHealthClient) SetRespError(err error) {
c.err = err
}

func (c *ConsulHealthClient) ServiceMultipleTags(service string, tags []string, passingOnly bool, q *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) {
func (c *ConsulHealthClient) ServiceMultipleTags(_ string, _ []string, _ bool, q *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) {
c.mutex.Lock()
defer c.mutex.Unlock()

Expand Down
Loading