From b2f5f90cdca79ef1340e20438795c62e1c0c73e2 Mon Sep 17 00:00:00 2001 From: Maceo Thompson Date: Tue, 1 Aug 2023 15:22:02 -0400 Subject: [PATCH] internal/scan: refactor to remove redundant code Since binary.go already uses build tags, the two removed files are now redundant. Replaced the call to the function in those files to a call to vulncheck.Binary directly. Change-Id: Ib1560a4303df2355ce7c121258aef091bab9ee01 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/514902 Run-TryBot: Maceo Thompson TryBot-Result: Gopher Robot Reviewed-by: Jonathan Amsterdam --- internal/scan/binary.go | 2 +- internal/scan/binary_118.go | 21 --------------------- internal/scan/binary_not118.go | 20 -------------------- 3 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 internal/scan/binary_118.go delete mode 100644 internal/scan/binary_not118.go diff --git a/internal/scan/binary.go b/internal/scan/binary.go index 76b17f75..abcc1314 100644 --- a/internal/scan/binary.go +++ b/internal/scan/binary.go @@ -32,7 +32,7 @@ func runBinary(ctx context.Context, handler govulncheck.Handler, cfg *config, cl if err := handler.Progress(p); err != nil { return err } - vr, err := binary(ctx, exe, &cfg.Config, client) + vr, err := vulncheck.Binary(ctx, exe, &cfg.Config, client) if err != nil { return fmt.Errorf("govulncheck: %v", err) } diff --git a/internal/scan/binary_118.go b/internal/scan/binary_118.go deleted file mode 100644 index d4345f3b..00000000 --- a/internal/scan/binary_118.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.18 -// +build go1.18 - -package scan - -import ( - "context" - "io" - - "golang.org/x/vuln/internal/client" - "golang.org/x/vuln/internal/govulncheck" - "golang.org/x/vuln/internal/vulncheck" -) - -func binary(ctx context.Context, exe io.ReaderAt, cfg *govulncheck.Config, client *client.Client) (_ *vulncheck.Result, err error) { - return vulncheck.Binary(ctx, exe, cfg, client) -} diff --git a/internal/scan/binary_not118.go b/internal/scan/binary_not118.go deleted file mode 100644 index 0f66a02c..00000000 --- a/internal/scan/binary_not118.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2022 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.18 -// +build !go1.18 - -package scan - -import ( - "context" - "errors" - "io" - - "golang.org/x/vuln/internal/vulncheck" -) - -func binary(ctx context.Context, exe io.ReaderAt, cfg *vulncheck.Config) (_ *vulncheck.Result, err error) { - return nil, errors.New("compile with Go 1.18 or higher to analyze binary files") -}