.PHONY: help init setup build run test test-race lint security generate mocks clean # ── Variables ────────────────────────────────────────────────────────────────── BINARY_NAME := app BINARY_PATH := ./bin/$(BINARY_NAME) CMD_PATH := ./cmd/app CONFIG_PATH := ./config/dev.yaml GO_FILES := $(shell find . -type f -name '*.go' -not -path './vendor/*') # ── Default target ───────────────────────────────────────────────────────────── help: ## Show this help message @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}' | sort # ── First-time setup ─────────────────────────────────────────────────────────── init: ## First-time project init: fetch deps, install tools, configure git hooks @echo "--- Fetching application dependencies ---" go get go.uber.org/zap@latest go get github.com/spf13/viper@latest go get github.com/stretchr/testify@latest go get github.com/stretchr/objx@latest @echo "--- Fetching tool dependencies (pinned in tools.go) ---" go get github.com/vektra/mockery/v2@latest go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest go get github.com/securego/gosec/v2/cmd/gosec@latest go get golang.org/x/vuln/cmd/govulncheck@latest go mod tidy @echo "--- Installing tool binaries ---" $(MAKE) tools @echo "--- Configuring git hooks ---" $(MAKE) setup @echo "Done! Run 'make build' to verify." setup: ## Configure git to use .githooks directory git config core.hooksPath .githooks chmod +x .githooks/* @echo "Git hooks configured: .githooks/" # ── Development tools ────────────────────────────────────────────────────────── tools: ## Install tool binaries to GOPATH/bin (versions from go.mod) @echo "Installing tools..." go install github.com/go-delve/delve/cmd/dlv@latest go install github.com/vektra/mockery/v2@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest go install github.com/securego/gosec/v2/cmd/gosec@latest go install golang.org/x/vuln/cmd/govulncheck@latest # ── Build ────────────────────────────────────────────────────────────────────── build: ## Compile the binary to ./bin/ go build -o $(BINARY_PATH) $(CMD_PATH) # ── Run ──────────────────────────────────────────────────────────────────────── run: ## Run the application with dev config CONFIG_PATH=$(CONFIG_PATH) go run $(CMD_PATH)/main.go # ── Test ─────────────────────────────────────────────────────────────────────── test: ## Run all tests go test ./... -cover test-race: ## Run all tests with race detector go test ./... -race -cover test-verbose: ## Run all tests with verbose output go test ./... -race -cover -v # ── Lint & Security ──────────────────────────────────────────────────────────── lint: ## Run golangci-lint golangci-lint run ./... lint-fix: ## Run golangci-lint with auto-fix golangci-lint run --fix ./... security: ## Run gosec + govulncheck @echo "--- gosec ---" gosec -quiet ./... @echo "--- govulncheck ---" govulncheck ./... # ── Code generation ──────────────────────────────────────────────────────────── generate: ## Run go generate across all packages go generate ./... mocks: ## Regenerate all mocks via mockery (config: .mockery.yaml) mockery # ── Cleanup ──────────────────────────────────────────────────────────────────── clean: ## Remove build artifacts and generated mocks rm -rf ./bin rm -rf ./mocks