From 761574c3cd35289b8fb830ae3f1971ffc433fda1 Mon Sep 17 00:00:00 2001 From: arriven <20084245+Arriven@users.noreply.github.com> Date: Sat, 23 Jul 2022 09:15:05 +0300 Subject: [PATCH] fix linter --- src/core/packetgen/connection.go | 7 +++---- src/job/packetgen.go | 12 ++++++------ src/job/rawnet.go | 4 ++-- src/utils/countrychecker.go | 4 ++-- src/utils/metrics/serve.go | 6 ++++-- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/core/packetgen/connection.go b/src/core/packetgen/connection.go index 015875e2..5a7fd6f8 100644 --- a/src/core/packetgen/connection.go +++ b/src/core/packetgen/connection.go @@ -23,7 +23,6 @@ package packetgen import ( - "context" "crypto/tls" "fmt" "net" @@ -42,7 +41,7 @@ type ConnectionConfig struct { Proxy *utils.ProxyParams } -func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error) { +func OpenConnection(c ConnectionConfig) (Connection, error) { switch c.Type { case "raw": var cfg rawConnConfig @@ -57,7 +56,7 @@ func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error) return nil, fmt.Errorf("error decoding connection config: %w", err) } - return openNetConn(ctx, cfg, c.Proxy) + return openNetConn(cfg, c.Proxy) default: return nil, fmt.Errorf("unknown connection type: %v", c.Type) } @@ -129,7 +128,7 @@ type netConn struct { target string } -func openNetConn(ctx context.Context, c netConnConfig, proxyParams *utils.ProxyParams) (*netConn, error) { +func openNetConn(c netConnConfig, proxyParams *utils.ProxyParams) (*netConn, error) { conn, err := utils.GetProxyFunc(utils.NonNilOrDefault(proxyParams, utils.ProxyParams{}), c.Protocol)(c.Protocol, c.Address) switch { diff --git a/src/job/packetgen.go b/src/job/packetgen.go index 88c67e97..a507fa38 100644 --- a/src/job/packetgen.go +++ b/src/job/packetgen.go @@ -49,7 +49,7 @@ func packetgenJob(ctx context.Context, args config.Args, globalConfig *GlobalCon ctx, cancel := context.WithCancel(ctx) defer cancel() - jobConfig, err := parsePacketgenArgs(ctx, args, globalConfig, a, logger) + jobConfig, err := parsePacketgenArgs(ctx, args, globalConfig, logger) if err != nil { return nil, fmt.Errorf("error parsing job config: %w", err) } @@ -72,7 +72,7 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob ctx, cancel := context.WithCancel(ctx) defer cancel() - conn, err := packetgen.OpenConnection(ctx, jobConfig.Connection) + conn, err := packetgen.OpenConnection(jobConfig.Connection) if err != nil { return err } @@ -131,8 +131,8 @@ func makePacketSource(ctx context.Context, logger *zap.Logger, packetTpls []*tem packetsChan := utils.InfiniteRange(ctx, packets) - return func(ctx context.Context, logger *zap.Logger) (packetgen.Packet, error) { - return getNextStaticPacket(ctx, logger, packetsChan) + return func(ctx context.Context, _ *zap.Logger) (packetgen.Packet, error) { + return getNextStaticPacket(ctx, packetsChan) }, nil } @@ -158,7 +158,7 @@ func staticPackets(ctx context.Context, logger *zap.Logger, packetTpls []*templa return packets, nil } -func getNextStaticPacket(ctx context.Context, logger *zap.Logger, packetsChan chan packetgen.Packet) (packetgen.Packet, error) { +func getNextStaticPacket(ctx context.Context, packetsChan chan packetgen.Packet) (packetgen.Packet, error) { select { case <-ctx.Done(): return packetgen.Packet{}, ctx.Err() @@ -251,7 +251,7 @@ func parsePackets(packets []packetDescriptor, dflt map[string]any) ([]*templates return packetTpls, nil } -func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *GlobalConfig, a *metrics.Accumulator, logger *zap.Logger) ( +func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *GlobalConfig, logger *zap.Logger) ( tpl *packetgenJobConfig, err error, ) { var jobConfig struct { diff --git a/src/job/rawnet.go b/src/job/rawnet.go index 2557748f..9221cbd0 100644 --- a/src/job/rawnet.go +++ b/src/job/rawnet.go @@ -46,7 +46,7 @@ func udpJob(ctx context.Context, args config.Args, globalConfig *GlobalConfig, a func rawnetJob(ctx context.Context, protocol string, args config.Args, globalConfig *GlobalConfig, a *metrics.Accumulator, logger *zap.Logger) ( data any, err error, ) { - packetgenArgs, err := parseRawNetJobArgs(logger, globalConfig, args, protocol) + packetgenArgs, err := parseRawNetJobArgs(globalConfig, args, protocol) if err != nil { return nil, err } @@ -54,7 +54,7 @@ func rawnetJob(ctx context.Context, protocol string, args config.Args, globalCon return packetgenJob(ctx, packetgenArgs, globalConfig, a, logger) } -func parseRawNetJobArgs(logger *zap.Logger, globalConfig *GlobalConfig, args config.Args, protocol string) ( +func parseRawNetJobArgs(globalConfig *GlobalConfig, args config.Args, protocol string) ( result map[string]any, err error, ) { var jobConfig struct { diff --git a/src/utils/countrychecker.go b/src/utils/countrychecker.go index e1044d89..0c06a55b 100644 --- a/src/utils/countrychecker.go +++ b/src/utils/countrychecker.go @@ -87,7 +87,7 @@ func getCountry(logger *zap.Logger, proxyParams ProxyParams, maxFetchRetries int for counter.Next() { logger.Info("checking IP address,", zap.Int("iter", counter.iter)) - if country, ip, err = fetchLocationInfo(logger, proxyParams); err != nil { + if country, ip, err = fetchLocationInfo(proxyParams); err != nil { logger.Warn("error fetching location info", zap.Error(err)) Sleep(context.Background(), backoffController.Increment().GetTimeout()) } else { @@ -98,7 +98,7 @@ func getCountry(logger *zap.Logger, proxyParams ProxyParams, maxFetchRetries int return "", "", fmt.Errorf("couldn't get location info in %d tries", maxFetchRetries) } -func fetchLocationInfo(logger *zap.Logger, proxyParams ProxyParams) (country, ip string, err error) { +func fetchLocationInfo(proxyParams ProxyParams) (country, ip string, err error) { const ( ipCheckerURI = "https://api.myip.com/" requestTimeout = 3 * time.Second diff --git a/src/utils/metrics/serve.go b/src/utils/metrics/serve.go index 5001b7e3..611731a2 100644 --- a/src/utils/metrics/serve.go +++ b/src/utils/metrics/serve.go @@ -26,8 +26,10 @@ func serveMetrics(ctx context.Context, logger *zap.Logger, listen string) { )) server := &http.Server{ - Addr: listen, - Handler: mux, + Addr: listen, + Handler: mux, + ReadTimeout: time.Second, + ReadHeaderTimeout: time.Second, } go func(ctx context.Context, server *http.Server) { <-ctx.Done()