Skip to content

Commit

Permalink
use go1.18 any
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Apr 1, 2022
1 parent c3d601b commit 16545e1
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 74 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Arriven/db1000n

go 1.17
go 1.18

require (
filippo.io/age v1.0.0
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/age v1.0.0 h1:V6q14n0mqYU3qKFkZ6oOaF9oXneOviS3ubXsSVBRSzc=
filippo.io/age v1.0.0/go.mod h1:PaX+Si/Sd5G8LgfCwldsSba3H1DDQZhIhFGkhbHaBq8=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic=
Expand Down Expand Up @@ -270,7 +269,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -334,7 +332,6 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down Expand Up @@ -401,14 +398,12 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
39 changes: 39 additions & 0 deletions golangci-lint.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
with import <nixpkgs>{};

buildGo118Module rec {
pname = "golangci-lint";
version = "1.45.2";

src = fetchFromGitHub {
owner = "golangci";
repo = "golangci-lint";
rev = "v${version}";
sha256 = "sha256-Mr45nJbpyzxo0ZPwx22JW2WrjyjI9FPpl+gZ7NIc6WQ=";
};

vendorSha256 = "sha256-pcbKg1ePN8pObS9EzP3QYjtaty27L9sroKUs/qEPtJo=";

doCheck = false;

subPackages = [ "cmd/golangci-lint" ];

nativeBuildInputs = [ installShellFiles ];

ldflags = [
"-s" "-w" "-X main.version=${version}" "-X main.commit=v${version}" "-X main.date=19700101-00:00:00"
];

postInstall = ''
for shell in bash zsh fish; do
HOME=$TMPDIR $out/bin/golangci-lint completion $shell > golangci-lint.$shell
installShellCompletion golangci-lint.$shell
done
'';

meta = with lib; {
description = "Fast linters Runner for Go";
homepage = "https://golangci-lint.run/";
license = licenses.gpl3Plus;
maintainers = with maintainers; [ anpryl manveru mic92 ];
};
}
2 changes: 1 addition & 1 deletion src/core/packetgen/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// ConnectionConfig describes which network to use when sending packets
type ConnectionConfig struct {
Type string
Args map[string]interface{}
Args map[string]any
}

func OpenConnection(c ConnectionConfig) (Connection, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/packetgen/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Packet struct {

type LayerConfig struct {
Type string
Data map[string]interface{}
Data map[string]any
}

type PacketConfig struct {
Expand Down
30 changes: 15 additions & 15 deletions src/core/packetgen/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@ import (
func TestSerialize(t *testing.T) {
t.Parallel()

configTpls := []map[string]interface{}{
configTpls := []map[string]any{
{
"network": map[string]interface{}{
"network": map[string]any{
"type": "ipv6",
"data": map[string]interface{}{
"data": map[string]any{
"src_ip": "{{ local_ipv6 }}",
"dst_ip": "{{ local_ipv6 }}",
},
},
"transport": map[string]interface{}{
"transport": map[string]any{
"type": "tcp",
"data": map[string]interface{}{
"data": map[string]any{
"src_port": "{{ random_port }}",
"dst_port": "{{ random_port }}",
"flags": map[string]interface{}{
"flags": map[string]any{
"syn": true,
},
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"type": "raw",
"data": map[string]interface{}{
"data": map[string]any{
"payload": "test",
},
},
"expected_result": "test",
},
{
"network": map[string]interface{}{
"network": map[string]any{
"type": "ipv4",
"data": map[string]interface{}{
"data": map[string]any{
"src_ip": "{{ local_ipv4 }}",
"dst_ip": "{{ local_ipv4 }}",
},
},
"transport": map[string]interface{}{
"transport": map[string]any{
"type": "tcp",
"data": map[string]interface{}{
"data": map[string]any{
"src_port": "{{ random_port }}",
"dst_port": "{{ random_port }}",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"type": "icmpv4",
"data": map[string]interface{}{
"data": map[string]any{
"type_code": 130,
"seq": 1231231,
"id": 1231231231,
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestSerialize(t *testing.T) {
}
}

func extractPayload(p gopacket.Packet, c map[string]interface{}) error {
func extractPayload(p gopacket.Packet, c map[string]any) error {
switch res := c["expected_result"].(type) {
case int:
if binary.BigEndian.Uint16(p.ApplicationLayer().Payload()) != uint16(res) {
Expand Down
2 changes: 1 addition & 1 deletion src/job/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewGlobalConfigWithFlags() *GlobalConfig {
}

// Job comment for linter
type Job = func(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error)
type Job = func(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error)

// Get job by type name
//nolint:cyclop // The string map alternative is orders of magnitude slower
Expand Down
4 changes: 2 additions & 2 deletions src/job/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/Arriven/db1000n/src/utils/templates"
)

func sequenceJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func sequenceJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down Expand Up @@ -64,7 +64,7 @@ func sequenceJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalCo
return nil, nil
}

func parallelJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func parallelJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion src/job/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

// Args is a generic arguments map.
type Args = map[string]interface{}
type Args = map[string]any

// Config for a single job.
type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion src/job/dnsblast.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type dnsBlastConfig struct {
ParallelQueries int
}

func dnsBlastJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func dnsBlastJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
jobConfig, err := getDNSBlastConfig(args, globalConfig)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions src/job/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import (
type httpJobConfig struct {
BasicJobConfig

Request map[string]interface{}
Client map[string]interface{} // See HTTPClientConfig
Request map[string]any
Client map[string]any // See HTTPClientConfig
}

func singleRequestJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func singleRequestJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down Expand Up @@ -85,8 +85,8 @@ func singleRequestJob(ctx context.Context, logger *zap.Logger, globalConfig *Glo
resp.Header.VisitAll(headerLoaderFunc(headers))
resp.Header.VisitAllCookie(cookieLoaderFunc(cookies, logger))

return map[string]interface{}{
"response": map[string]interface{}{
return map[string]any{
"response": map[string]any{
"body": string(resp.Body()),
"status_code": resp.StatusCode(),
"headers": headers,
Expand Down Expand Up @@ -121,7 +121,7 @@ func cookieLoaderFunc(cookies map[string]string, logger *zap.Logger) func(key []
}
}

func fastHTTPJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func fastHTTPJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down
4 changes: 2 additions & 2 deletions src/job/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type packetgenJobConfig struct {
Connection packetgen.ConnectionConfig
}

func packetgenJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func packetgenJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down Expand Up @@ -104,7 +104,7 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob
func parsePacketgenArgs(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (tpl *packetgenJobConfig, err error) {
var jobConfig struct {
BasicJobConfig
Packet map[string]interface{}
Packet map[string]any
Connection packetgen.ConnectionConfig
}

Expand Down
4 changes: 2 additions & 2 deletions src/job/rawnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type rawnetConfig struct {
timeout time.Duration
}

func tcpJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func tcpJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down Expand Up @@ -125,7 +125,7 @@ func sendTCP(ctx context.Context, logger *zap.Logger, jobConfig *rawnetConfig, t
return nil
}

func udpJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func udpJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion src/job/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *Runner) runJobs(ctx context.Context, logger *zap.Logger, cfg *config.Mu
cfg.Jobs[i].Count *= r.globalJobsCfg.ScaleFactor
}

cfgMap := make(map[string]interface{})
cfgMap := make(map[string]any)
if err := utils.Decode(cfg.Jobs[i], &cfgMap); err != nil {
logger.Fatal("failed to encode cfg map")
}
Expand Down
2 changes: 1 addition & 1 deletion src/job/slowloris.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/Arriven/db1000n/src/utils/templates"
)

func slowLorisJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func slowLorisJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down
10 changes: 5 additions & 5 deletions src/job/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

func logJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args config.Args) (
data interface{}, err error, //nolint:unparam // data is here to match Job
data any, err error, //nolint:unparam // data is here to match Job
) {
var jobConfig struct {
Text string
Expand All @@ -51,7 +51,7 @@ func logJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args confi
return nil, nil
}

func setVarJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args config.Args) (data interface{}, err error) {
func setVarJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args config.Args) (data any, err error) {
var jobConfig struct {
Value string
}
Expand All @@ -64,7 +64,7 @@ func setVarJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args co
}

func checkJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args config.Args) (
data interface{}, err error, //nolint:unparam // data is here to match Job
data any, err error, //nolint:unparam // data is here to match Job
) {
var jobConfig struct {
Value string
Expand All @@ -81,7 +81,7 @@ func checkJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args con
return nil, nil
}

func loopJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func loopJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down Expand Up @@ -122,7 +122,7 @@ func isInEncryptedContext(ctx context.Context) bool {
return ctx.Value(templates.ContextKey(isEncryptedContextKey)) != nil
}

func encryptedJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data interface{}, err error) {
func encryptedJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
if globalConfig.SkipEncrypted {
return nil, fmt.Errorf("app is configured to skip encrypted jobs")
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (ms *Storage) Read(name string) uint64 {
var sum uint64

if tracker, ok := ms.trackers[name]; ok {
tracker.metrics.Range(func(k, v interface{}) bool {
tracker.metrics.Range(func(k, v any) bool {
if value, ok := v.(uint64); ok {
sum += value
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ota/shared.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ota

func appendArgIfNotPresent(osArgs, extraArgs []string) []string {
osArgsMap := make(map[string]interface{}, len(osArgs))
osArgsMap := make(map[string]any, len(osArgs))
for _, osArg := range osArgs {
osArgsMap[osArg] = nil
}
Expand Down
Loading

0 comments on commit 16545e1

Please sign in to comment.