Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Jan 25, 2025
1 parent f5f6734 commit 4f184fb
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ linters-settings:
- "github.com/google/go-cmp"
- "github.com/google/go-github/v53/github"
- "github.com/codingsince1985/checksum"
- "golang.org/x/exp/maps"
- "golang.org/x/exp/slices"
- "gopkg.in/yaml.v3"
- "github.com/zenizh/go-capturer"
- "gopkg.in/natefinch/lumberjack.v2"
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"net/http"
"os"
"path"
Expand All @@ -24,7 +25,6 @@ import (
"github.com/google/go-github/v53/github"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
yamlv3 "gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -162,7 +162,7 @@ var pluginInstallCmd = &cobra.Command{

// Check if the plugin is already installed and prompt the user to confirm the update.
if len(existingPluginURLs) > 0 {
pluginNames := strings.Join(maps.Keys[map[string]string](existingPluginURLs), ", ")
pluginNames := strings.Join(slices.Sorted(maps.Keys(existingPluginURLs)), ", ")
cmd.Printf("The following plugins are already installed: %s\n", pluginNames)

if noPrompt {
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"log"
"maps"
"os"
"syscall"

Expand All @@ -13,7 +14,6 @@ import (
"github.com/getsentry/sentry-go"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"golang.org/x/exp/maps"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math"
"os"
"reflect"
"slices"
"sort"
"strings"

Expand All @@ -21,7 +22,6 @@ import (
"github.com/knadh/koanf/providers/structs"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/exp/slices"
)

type IConfig interface {
Expand Down
11 changes: 6 additions & 5 deletions metrics/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"context"
"io"
"maps"
"net"
"net/http"
"os"
"sort"
"slices"
"strings"
"time"

Expand All @@ -21,7 +22,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -190,8 +190,7 @@ func (m *Merger) MergeMetrics(pluginMetrics map[string][]byte) *gerr.GatewayDErr
}

// Sort metrics by name and encode them.
metricNames := maps.Keys(metricFamilies)
sort.Strings(metricNames)
metricNames := slices.Sorted(maps.Keys(metricFamilies))
for _, metric := range metricNames {
err := enc.Encode(metricFamilies[metric])
if err != nil {
Expand Down Expand Up @@ -236,7 +235,9 @@ func (m *Merger) Start() {
StartAt(startDelay).
Do(func() {
_, span := otel.Tracer(config.TracerName).Start(ctx, "Merge metrics")
span.SetAttributes(attribute.StringSlice("plugins", maps.Keys(m.Addresses)))
span.SetAttributes(
attribute.StringSlice("plugins", slices.Sorted(maps.Keys(m.Addresses))),
)
defer span.End()

m.Logger.Trace().Msg(
Expand Down
8 changes: 4 additions & 4 deletions network/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func BenchmarkNewClient(b *testing.B) {
}

logger := logging.NewLogger(context.Background(), cfg)
for i := 0; i < b.N; i++ {
for range b.N {
client := NewClient(context.Background(), &config.Client{
Network: "tcp",
Address: "localhost:5432",
Expand Down Expand Up @@ -160,7 +160,7 @@ func BenchmarkSend(b *testing.B) {
defer client.Close()

packet := CreatePgStartupPacket()
for i := 0; i < b.N; i++ {
for range b.N {
client.Send(packet) //nolint:errcheck
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func BenchmarkReceive(b *testing.B) {

packet := CreatePgStartupPacket()
client.Send(packet) //nolint:errcheck
for i := 0; i < b.N; i++ {
for range b.N {
client.Receive() //nolint:errcheck
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func BenchmarkIsConnected(b *testing.B) {
logger, nil)
defer client.Close()

for i := 0; i < b.N; i++ {
for range b.N {
client.IsConnected()
}
}
10 changes: 5 additions & 5 deletions network/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func BenchmarkNewProxy(b *testing.B) {
})

// Create a proxy with a fixed buffer newPool
for i := 0; i < b.N; i++ {
for range b.N {
proxy := NewProxy(
context.Background(),
Proxy{
Expand Down Expand Up @@ -195,7 +195,7 @@ func BenchmarkProxyConnectDisconnect(b *testing.B) {
conn := testConnection{}

// Connect to the proxy
for i := 0; i < b.N; i++ {
for range b.N {
proxy.Connect(conn.ConnWrapper) //nolint:errcheck
proxy.Disconnect(conn.ConnWrapper) //nolint:errcheck
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func BenchmarkProxyPassThrough(b *testing.B) {
stack := NewStack()

// Connect to the proxy
for i := 0; i < b.N; i++ {
for range b.N {
proxy.PassThroughToClient(conn.ConnWrapper, stack) //nolint:errcheck
proxy.PassThroughToServer(conn.ConnWrapper, stack) //nolint:errcheck
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func BenchmarkProxyIsHealthyAndIsExhausted(b *testing.B) {
defer proxy.Disconnect(conn.ConnWrapper) //nolint:errcheck

// Connect to the proxy
for i := 0; i < b.N; i++ {
for range b.N {
proxy.IsHealthy(client) //nolint:errcheck
proxy.IsExhausted()
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func BenchmarkProxyAvailableAndBusyConnectionsString(b *testing.B) {
defer proxy.Disconnect(conn.ConnWrapper) //nolint:errcheck

// Connect to the proxy
for i := 0; i < b.N; i++ {
for range b.N {
proxy.AvailableConnectionsString()
proxy.BusyConnectionsString()
}
Expand Down
12 changes: 6 additions & 6 deletions network/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func BenchmarkGetID(b *testing.B) {
logger := logging.NewLogger(context.Background(), cfg)
for _, seed := range seedValues {
b.Run(fmt.Sprintf("seed=%d", seed), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
GetID("tcp", "localhost:5432", seed, logger)
}
})
Expand All @@ -76,7 +76,7 @@ func BenchmarkResolveUDP(b *testing.B) {
}

logger := logging.NewLogger(context.Background(), cfg)
for i := 0; i < b.N; i++ {
for range b.N {
Resolve("udp", "localhost:53", logger) //nolint:errcheck
}
}
Expand All @@ -91,7 +91,7 @@ func BenchmarkResolveTCP(b *testing.B) {
}

logger := logging.NewLogger(context.Background(), cfg)
for i := 0; i < b.N; i++ {
for range b.N {
Resolve("tcp", "localhost:5432", logger) //nolint:errcheck
}
}
Expand All @@ -106,7 +106,7 @@ func BenchmarkResolveUnix(b *testing.B) {
}

logger := logging.NewLogger(context.Background(), cfg)
for i := 0; i < b.N; i++ {
for range b.N {
Resolve("unix", "/tmp/unix.sock", logger) //nolint:errcheck
}
}
Expand Down Expand Up @@ -157,13 +157,13 @@ func BenchmarkTrafficData(b *testing.B) {
},
}
err := "test error"
for i := 0; i < b.N; i++ {
for range b.N {
trafficData(conn.Conn(), client, fields, err)
}
}

func BenchmarkExtractFieldValue(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
extractFieldValue(
map[string]any{
"test": "test",
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func BenchmarkHookRun(b *testing.B) {
hookFunction,
)
}
for i := 0; i < b.N; i++ {
for range b.N {
//nolint:errcheck
reg.Run(
context.Background(),
Expand Down
18 changes: 9 additions & 9 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,23 @@ func TestPool_Cap(t *testing.T) {
}

func BenchmarkNewPool(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
NewPool(context.Background(), config.EmptyPoolCapacity)
}
}

func BenchmarkPool_PutPop(b *testing.B) {
pool := NewPool(context.Background(), config.EmptyPoolCapacity)
defer pool.Clear()
for i := 0; i < b.N; i++ {
for range b.N {
pool.Put("client1.ID", "client1") //nolint:errcheck
pool.Pop("client1.ID")
}
}

func BenchmarkPool_Clear(b *testing.B) {
pool := NewPool(context.Background(), config.EmptyPoolCapacity)
for i := 0; i < b.N; i++ {
for range b.N {
pool.Clear()
}
}
Expand All @@ -252,7 +252,7 @@ func BenchmarkPool_ForEach(b *testing.B) {
defer pool.Clear()
pool.Put("client1.ID", "client1") //nolint:errcheck
pool.Put("client2.ID", "client2") //nolint:errcheck
for i := 0; i < b.N; i++ {
for range b.N {
pool.ForEach(func(_, _ any) bool {
return true
})
Expand All @@ -264,7 +264,7 @@ func BenchmarkPool_Get(b *testing.B) {
defer pool.Clear()
pool.Put("client1.ID", "client1") //nolint:errcheck
pool.Put("client2.ID", "client2") //nolint:errcheck
for i := 0; i < b.N; i++ {
for range b.N {
pool.Get("client1.ID")
pool.Get("client2.ID")
}
Expand All @@ -275,7 +275,7 @@ func BenchmarkPool_GetOrPut(b *testing.B) {
defer pool.Clear()
pool.Put("client1.ID", "client1") //nolint:errcheck
pool.Put("client2.ID", "client2") //nolint:errcheck
for i := 0; i < b.N; i++ {
for range b.N {
pool.GetOrPut("client1.ID", "client1") //nolint:errcheck
pool.GetOrPut("client2.ID", "client2") //nolint:errcheck
}
Expand All @@ -284,7 +284,7 @@ func BenchmarkPool_GetOrPut(b *testing.B) {
func BenchmarkPool_Remove(b *testing.B) {
pool := NewPool(context.Background(), config.EmptyPoolCapacity)
defer pool.Clear()
for i := 0; i < b.N; i++ {
for range b.N {
pool.Put("client1.ID", "client1") //nolint:errcheck
pool.Remove("client1.ID")
}
Expand All @@ -293,15 +293,15 @@ func BenchmarkPool_Remove(b *testing.B) {
func BenchmarkPool_Size(b *testing.B) {
pool := NewPool(context.Background(), config.EmptyPoolCapacity)
defer pool.Clear()
for i := 0; i < b.N; i++ {
for range b.N {
pool.Size()
}
}

func BenchmarkPool_Cap(b *testing.B) {
pool := NewPool(context.Background(), config.EmptyPoolCapacity)
defer pool.Clear()
for i := 0; i < b.N; i++ {
for range b.N {
pool.Cap()
}
}

0 comments on commit 4f184fb

Please sign in to comment.