Last active
January 19, 2022 19:35
-
-
Save marcelohmariano/80bfa10f84506905d34dd813b3eebba5 to your computer and use it in GitHub Desktop.
Use go mod to manage go tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHELL := /bin/sh | |
BIN := bin | |
define ADD_TOOL_BINARY_RULE | |
TOOLS_BINARIES += $$(BIN)/$$(notdir $(1)) | |
$$(lastword $$(TOOLS_BINARIES)): | |
@go build -o $$@ $(1) | |
endef | |
TOOLS := $(shell go list -f '{{range .Imports}} {{- .}} {{end}}' tools.go) | |
$(foreach tool,$(TOOLS),$(eval $(call ADD_TOOL_BINARY_RULE,$(tool)))) | |
.PHONY: fix-imports | |
fix-imports: tools | |
@$(BIN)/goimports -l -w . | |
.PHONY: lint | |
lint: tools | |
@$(BIN)/golangci-lint run ./... | |
tools: tidy $(TOOLS_BINARIES) | |
.PHONY: tidy | |
tidy: | |
@go mod tidy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:build tools | |
// +build tools | |
package main | |
import ( | |
_ "github.com/golangci/golangci-lint/cmd/golangci-lint" | |
_ "golang.org/x/tools/cmd/goimports" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment