Skip to content

Instantly share code, notes, and snippets.

@marcelohmariano
Last active January 19, 2022 19:35
Show Gist options
  • Save marcelohmariano/80bfa10f84506905d34dd813b3eebba5 to your computer and use it in GitHub Desktop.
Save marcelohmariano/80bfa10f84506905d34dd813b3eebba5 to your computer and use it in GitHub Desktop.
Use go mod to manage go tools
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
//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