Skip to content

Commit f69203f

Browse files
authored
chore: use go tool [IDE-1377] (#114)
1 parent 6593ff3 commit f69203f

File tree

13 files changed

+38
-40
lines changed

13 files changed

+38
-40
lines changed

Makefile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ PACT_CLI_TARGETS := $(TOOLS_BIN)/pact/bin/pact-broker $(TOOLS_BIN)/.pact_$(PACT_
1212
PACT_GO_V := v2.4.1
1313
PACT_GO_LIB_TARGETS := /tmp/.libpact-ffi_$(PACT_GO_V) # Only use a marker file since lib extension is either .so or .dll
1414

15-
SHELL:=env PATH=$(TOOLS_BIN)/go:$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL)
15+
SHELL:=env PATH=$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL)
1616

1717
## tools: Install required tooling.
1818
.PHONY: tools
19-
tools: $(TOOLS_BIN)/go $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)
19+
tools: $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)
2020

2121
$(TOOLS_BIN):
2222
@mkdir -p $(TOOLS_BIN)
@@ -31,13 +31,9 @@ $(PACT_CLI_TARGETS): $(TOOLS_BIN)
3131
@cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=$(PACT_CLI_V) bash; cd ../
3232
@touch $(TOOLS_BIN)/.pact_$(PACT_CLI_V)
3333

34-
$(TOOLS_BIN)/go:
35-
mkdir -p ${TOOLS_BIN}/go
36-
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % sh -c 'GOBIN=${TOOLS_BIN}/go go install %'
37-
38-
$(PACT_GO_LIB_TARGETS): $(TOOLS_BIN)/go
34+
$(PACT_GO_LIB_TARGETS):
3935
@rm -f /tmp/.libpact-ffi_*
40-
@GOBIN=${TOOLS_BIN}/go ${TOOLS_BIN}/go/pact-go -l DEBUG install -d /tmp
36+
@go tool github.com/pact-foundation/pact-go/v2 -l DEBUG install -d /tmp
4137
@touch /tmp/.libpact-ffi_$(PACT_GO_V)
4238

4339
.PHONY: format
@@ -101,11 +97,11 @@ generate:
10197
endif
10298

10399
.PHONY: generate-mocks
104-
generate-mocks: $(TOOLS_BIN)/go/mockgen
100+
generate-mocks:
105101
@go generate -tags MOCK ./...
106102

107103
.PHONY: generate-apis
108-
generate-apis: $(TOOLS_BIN)/go/oapi-codegen download-apis
104+
generate-apis: download-apis
109105
@go generate -tags API,!MOCK ./...
110106

111107
.PHONY: download-apis

bundle/bundle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package bundle
1919
import (
2020
"context"
2121
"fmt"
22+
2223
"github.com/rs/zerolog"
2324

2425
"github.com/snyk/code-client-go/internal/deepcode"
2526
"github.com/snyk/code-client-go/observability"
2627
)
2728

28-
//go:generate mockgen -destination=mocks/bundle.go -source=bundle.go -package mocks
29+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/bundle.go -source=bundle.go -package mocks
30+
2931
type Bundle interface {
3032
UploadBatch(ctx context.Context, requestId string, batch *Batch) error
3133
GetBundleHash() string

bundle/bundle_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ import (
2121
"os"
2222
"path/filepath"
2323

24-
"github.com/snyk/code-client-go/scan"
25-
2624
"github.com/puzpuzpuz/xsync"
2725
"github.com/rs/zerolog"
2826

2927
"github.com/snyk/code-client-go/internal/deepcode"
3028
"github.com/snyk/code-client-go/internal/util"
3129
"github.com/snyk/code-client-go/observability"
30+
"github.com/snyk/code-client-go/scan"
3231
)
3332

33+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/bundle_manager.go -source=bundle_manager.go -package mocks
34+
3435
type bundleManager struct {
3536
deepcodeClient deepcode.DeepcodeClient
3637
instrumentor observability.Instrumentor
@@ -41,7 +42,6 @@ type bundleManager struct {
4142
supportedConfigFiles *xsync.MapOf[string, bool]
4243
}
4344

44-
//go:generate mockgen -destination=mocks/bundle_manager.go -source=bundle_manager.go -package mocks
4545
type BundleManager interface {
4646
Create(ctx context.Context,
4747
requestId string,

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package config
22

33
import "time"
44

5+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/config.go -source=config.go -package mocks
6+
57
// Config defines the configurable options for the HTTP client.
6-
//
7-
//go:generate mockgen -destination=mocks/config.go -source=config.go -package mocks
88
type Config interface {
99

1010
// Organization is the Snyk organization in which code SAST is being run.

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/golang/mock v1.6.0
88
github.com/google/uuid v1.6.0
99
github.com/hexops/gotextdiff v1.0.3
10-
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
1110
github.com/oapi-codegen/runtime v1.1.1
1211
github.com/pact-foundation/pact-go/v2 v2.4.1
1312
github.com/pkg/errors v0.9.1
@@ -44,6 +43,7 @@ require (
4443
github.com/mattn/go-colorable v0.1.13 // indirect
4544
github.com/mattn/go-isatty v0.0.20 // indirect
4645
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
46+
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
4747
github.com/perimeterx/marshmallow v1.1.5 // indirect
4848
github.com/pjbgf/sha1cd v0.3.2 // indirect
4949
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -68,3 +68,9 @@ require (
6868
gopkg.in/yaml.v2 v2.4.0 // indirect
6969
gopkg.in/yaml.v3 v3.0.1 // indirect
7070
)
71+
72+
tool (
73+
github.com/golang/mock/mockgen
74+
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
75+
github.com/pact-foundation/pact-go/v2
76+
)

http/http.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
"github.com/snyk/code-client-go/observability"
2929
)
3030

31-
//go:generate mockgen -destination=mocks/http.go -source=http.go -package mocks
31+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/http.go -source=http.go -package mocks
32+
3233
type HTTPClient interface {
3334
Do(req *http.Request) (*http.Response, error)
3435
}

internal/analysis/analysis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import (
4242
"github.com/snyk/code-client-go/scan"
4343
)
4444

45-
//go:generate mockgen -destination=mocks/analysis.go -source=analysis.go -package mocks
45+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/analysis.go -source=analysis.go -package mocks
46+
4647
type AnalysisOrchestrator interface {
4748
RunTest(ctx context.Context, orgId string, b bundle.Bundle, target scan.Target, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
4849
RunTestRemote(ctx context.Context, orgId string, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)

internal/api/test/2024-12-21/gen.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
package v20241221
55

6-
//go:generate oapi-codegen --config common/common.config.yaml common/common.yaml
7-
//go:generate oapi-codegen --config parameters/orgs.config.yaml parameters/orgs.yaml
8-
//go:generate oapi-codegen --config parameters/tests.config.yaml parameters/tests.yaml
9-
//go:generate oapi-codegen --config models/tests.config.yaml models/tests.yaml
10-
//go:generate oapi-codegen --config spec.config.yaml spec.yaml
6+
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config common/common.config.yaml common/common.yaml
7+
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config parameters/orgs.config.yaml parameters/orgs.yaml
8+
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config parameters/tests.config.yaml parameters/tests.yaml
9+
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config models/tests.config.yaml models/tests.yaml
10+
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config spec.config.yaml spec.yaml

internal/deepcode/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import (
3636
"github.com/snyk/code-client-go/observability"
3737
)
3838

39-
//go:generate mockgen -destination=mocks/client.go -source=client.go -package mocks
39+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/client.go -source=client.go -package mocks
40+
4041
type DeepcodeClient interface {
4142
GetFilters(ctx context.Context) (
4243
filters FiltersResponse,

observability/error_reporter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package observability
22

3-
//go:generate mockgen -destination=mocks/error_reporter.go -source=error_reporter.go -package mocks
3+
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/error_reporter.go -source=error_reporter.go -package mocks
4+
45
type ErrorReporter interface {
56
FlushErrorReporting()
67
CaptureError(err error, options ErrorReporterOptions) bool

0 commit comments

Comments
 (0)