Add Go module and Makefile
This commit is contained in:
@@ -0,0 +1,146 @@
|
|||||||
|
MODULE := code.chimeric.al/dwrz/dqs
|
||||||
|
CMDS := $(notdir $(wildcard ./cmd/*))
|
||||||
|
BINARIES := $(addprefix bin/,$(CMDS))
|
||||||
|
|
||||||
|
GO := go
|
||||||
|
GOFMT := go fmt
|
||||||
|
GOVET := go vet
|
||||||
|
GOIMPORTS := go tool goimports
|
||||||
|
DEADCODE := go tool deadcode
|
||||||
|
GOFIX := $(GO) fix
|
||||||
|
GOVULNCHECK := go tool govulncheck
|
||||||
|
STATICCHECK := go tool staticcheck
|
||||||
|
|
||||||
|
BUILDFLAGS := -buildvcs=true
|
||||||
|
PLATFORMS := linux/amd64
|
||||||
|
|
||||||
|
.PHONY: all build build-all buildinfo check clean deadcode deps fix fmt help \
|
||||||
|
imports install lint run staticcheck test tidy tools uninstall \
|
||||||
|
verify vet vulncheck $(CMDS)
|
||||||
|
|
||||||
|
## Build all binaries (default target)
|
||||||
|
all: build
|
||||||
|
|
||||||
|
## Display this help screen
|
||||||
|
help:
|
||||||
|
@awk ' \
|
||||||
|
/^##/ { doc = substr($$0, 4); next } \
|
||||||
|
/^[a-zA-Z0-9_-]+:/ && doc { \
|
||||||
|
split($$1, target, ":"); \
|
||||||
|
printf "\033[36m%-20s\033[0m %s\n", target[1], doc; \
|
||||||
|
doc = "" \
|
||||||
|
} \
|
||||||
|
' $(MAKEFILE_LIST)
|
||||||
|
|
||||||
|
## Build all binaries to bin/
|
||||||
|
build: $(BINARIES)
|
||||||
|
|
||||||
|
## Build binaries for all defined platforms
|
||||||
|
build-all:
|
||||||
|
@for cmd in $(CMDS); do \
|
||||||
|
for platform in $(PLATFORMS); do \
|
||||||
|
echo "Building $$cmd for $$platform..."; \
|
||||||
|
out="bin/$$cmd-$${platform%/*}-$${platform#*/}"; \
|
||||||
|
GOOS=$${platform%/*} GOARCH=$${platform#*/} \
|
||||||
|
$(GO) build $(BUILDFLAGS) -o $$out ./cmd/$$cmd; \
|
||||||
|
done; \
|
||||||
|
done
|
||||||
|
|
||||||
|
## Build specific binaries (pattern rule)
|
||||||
|
bin/%: ./cmd/%
|
||||||
|
$(GO) build $(BUILDFLAGS) -o $@ ./$<
|
||||||
|
|
||||||
|
## Shortcut targets to build specific commands (e.g., 'make admin')
|
||||||
|
$(CMDS):
|
||||||
|
$(GO) build $(BUILDFLAGS) -o bin/$@ ./cmd/$@
|
||||||
|
|
||||||
|
## Show version info for built binaries
|
||||||
|
buildinfo: build
|
||||||
|
@for bin in $(BINARIES); do \
|
||||||
|
if [ -x $$bin ]; then \
|
||||||
|
echo "Info for $$bin:"; \
|
||||||
|
$(GO) version -m $$bin || true; \
|
||||||
|
fi; \
|
||||||
|
done
|
||||||
|
|
||||||
|
## Run tests with race detection and coverage
|
||||||
|
test:
|
||||||
|
$(GO) test -cover -race ./...
|
||||||
|
|
||||||
|
## Run all linters (fmt, vet, imports, deadcode, vulncheck)
|
||||||
|
lint: fix fmt imports vet deadcode vulncheck staticcheck
|
||||||
|
|
||||||
|
## Automatically fix code for newer Go versions
|
||||||
|
fix:
|
||||||
|
$(GOFIX) ./...
|
||||||
|
|
||||||
|
## Format code using go fmt
|
||||||
|
fmt:
|
||||||
|
$(GOFMT) ./...
|
||||||
|
|
||||||
|
## Fix imports and format using goimports
|
||||||
|
imports:
|
||||||
|
find . -type f -name '*.go' -not -path './vendor/*' | \
|
||||||
|
xargs $(GOIMPORTS) -w -local "$(MODULE)"
|
||||||
|
|
||||||
|
## Run go vet
|
||||||
|
vet:
|
||||||
|
$(GOVET) ./...
|
||||||
|
|
||||||
|
## Find dead code
|
||||||
|
deadcode:
|
||||||
|
$(DEADCODE) ./...
|
||||||
|
|
||||||
|
## Check for vulnerabilities
|
||||||
|
vulncheck:
|
||||||
|
$(GOVULNCHECK) ./...
|
||||||
|
|
||||||
|
## Run integration checks (alias for lint)
|
||||||
|
check: lint
|
||||||
|
|
||||||
|
## Tidy go.mod dependencies
|
||||||
|
tidy:
|
||||||
|
$(GO) mod tidy
|
||||||
|
|
||||||
|
## Run staticcheck
|
||||||
|
staticcheck:
|
||||||
|
$(STATICCHECK) ./...
|
||||||
|
|
||||||
|
## Download dependencies
|
||||||
|
deps:
|
||||||
|
$(GO) mod download
|
||||||
|
|
||||||
|
## Verify dependencies
|
||||||
|
verify:
|
||||||
|
$(GO) mod verify
|
||||||
|
|
||||||
|
## Install development tools
|
||||||
|
tools:
|
||||||
|
go get -tool golang.org/x/tools/cmd/deadcode@latest
|
||||||
|
go get -tool golang.org/x/tools/cmd/goimports@latest
|
||||||
|
go get -tool golang.org/x/vuln/cmd/govulncheck@latest
|
||||||
|
go get -tool honnef.co/go/tools/cmd/staticcheck@latest
|
||||||
|
|
||||||
|
## Run the specified CMD binary (use ARGS="..." to pass arguments)
|
||||||
|
# trap '' INT prevents colorize-logs from exiting immediately on Ctrl-C,
|
||||||
|
# allowing it to print remaining output before the application terminates.
|
||||||
|
run: clean bin/$(CMD) ./bin/$(CMD) $(ARGS)
|
||||||
|
|
||||||
|
## Clean build artifacts
|
||||||
|
clean:
|
||||||
|
$(GO) clean
|
||||||
|
rm -f bin/*
|
||||||
|
|
||||||
|
## Install binaries to $GOBIN
|
||||||
|
install:
|
||||||
|
$(GO) install $(BUILDFLAGS) ./cmd/...
|
||||||
|
|
||||||
|
## Uninstall binaries from $GOBIN
|
||||||
|
uninstall:
|
||||||
|
@for cmd in $(CMDS); do \
|
||||||
|
path=$$( $(GO) env GOBIN )/$$cmd; \
|
||||||
|
if [ -z "$$( $(GO) env GOBIN )" ]; \
|
||||||
|
then path=$$( $(GO) env GOPATH )/bin/$$cmd; fi; \
|
||||||
|
echo "Removing $$path"; \
|
||||||
|
rm -f $$path; \
|
||||||
|
done
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
module code.chimeric.al/dwrz/dqs
|
||||||
|
|
||||||
|
go 1.27.2
|
||||||
|
|
||||||
|
tool (
|
||||||
|
golang.org/x/tools/cmd/deadcode
|
||||||
|
golang.org/x/tools/cmd/goimports
|
||||||
|
golang.org/x/vuln/cmd/govulncheck
|
||||||
|
honnef.co/go/tools/cmd/staticcheck
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
|
||||||
|
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect
|
||||||
|
golang.org/x/mod v0.42.0 // indirect
|
||||||
|
golang.org/x/sync v0.24.0 // indirect
|
||||||
|
golang.org/x/sys v0.49.0 // indirect
|
||||||
|
golang.org/x/telemetry v0.0.0-20261010193011-f71dc92da45e // indirect
|
||||||
|
golang.org/x/tools v0.52.0 // indirect
|
||||||
|
golang.org/x/vuln v1.9.0 // indirect
|
||||||
|
honnef.co/go/tools v0.8.2 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
|
||||||
|
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RAtvaGgKxc+8FQIpxHgsF+HBzPyYL2cyVU=
|
||||||
|
github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
|
github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
|
||||||
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
|
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=
|
||||||
|
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
|
||||||
|
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
|
||||||
|
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
|
||||||
|
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||||
|
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||||
|
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
|
||||||
|
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||||
|
golang.org/x/telemetry v0.0.0-20261010193011-f71dc92da45e h1:P6NGsugec4oASJ+yKMNgTndeo0h2CbixZLvQIe9h5R4=
|
||||||
|
golang.org/x/telemetry v0.0.0-20261010193011-f71dc92da45e/go.mod h1:GNu+nb+E5axfGmP+Uu3ZVQu5lE/Xk42MjZOHWUD94/o=
|
||||||
|
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
|
||||||
|
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
|
||||||
|
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
|
||||||
|
golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
|
||||||
|
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
|
||||||
|
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
|
||||||
|
golang.org/x/vuln v1.9.0 h1:12VaqnI9kJfqwRoPptxoqsUhQtdfrSbdksT7X/KY/sc=
|
||||||
|
golang.org/x/vuln v1.9.0/go.mod h1:E/Frwm0xp49fTyBW+6CQHdkvobknbwUM49yEpMGUauw=
|
||||||
|
honnef.co/go/tools v0.8.2 h1:+jPbCzuYxYrcoOvCecYUFDj+XJQRmzIhJmlbpps21Zk=
|
||||||
|
honnef.co/go/tools v0.8.2/go.mod h1:xG1Q4n+mg3bKZrO6RWFA9jFlkqplflmDRHGeuexiLDs=
|
||||||
Reference in New Issue
Block a user