feat: improve resource routing API and add comprehensive quality standards
BREAKING CHANGES:
- Renamed HandleGET -> MemberGET for member-level routes
- Renamed HandlePOST -> MemberPOST for member-level routes
- Renamed HandlePUT -> MemberPUT for member-level routes
- Renamed HandlePATCH -> MemberPATCH for member-level routes
- Renamed HandleDELETE -> MemberDELETE for member-level routes
New Features:
- Added collection-level route methods: GET, POST, PUT, PATCH, DELETE
- Clear distinction between collection (/pattern/action) and member (/pattern/{id}/action) routes
- Comprehensive documentation (README, CONTRIBUTING, QUICKSTART, DOCS)
- Development tooling (Makefile, check.sh script)
- AI coding assistant guidelines (.cursorrules)
- GitHub Actions CI/CD pipeline
- golangci-lint configuration
Code Quality:
- Optimized struct field alignment for better memory usage
- All code passes go vet, staticcheck, and fieldalignment
- All tests pass with race detector
- Go 1.25+ requirement enforced
Documentation:
- Complete README rewrite with examples
- CONTRIBUTING.md with development guidelines
- QUICKSTART.md for new users
- CHANGELOG.md with version history
- SUMMARY.md documenting all changes
- DOCS.md as documentation index
This commit is contained in:
128
Makefile
Normal file
128
Makefile
Normal file
@@ -0,0 +1,128 @@
|
||||
.PHONY: help test vet staticcheck fieldalignment check coverage bench clean install-tools fmt tidy run-example
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@echo "Mux - Development Commands"
|
||||
@echo ""
|
||||
@echo "Usage: make [target]"
|
||||
@echo ""
|
||||
@echo "Targets:"
|
||||
@echo " help Show this help message"
|
||||
@echo " test Run tests"
|
||||
@echo " test-race Run tests with race detector"
|
||||
@echo " vet Run go vet"
|
||||
@echo " staticcheck Run staticcheck"
|
||||
@echo " fieldalignment Check and report field alignment issues"
|
||||
@echo " fieldalignment-fix Automatically fix field alignment issues"
|
||||
@echo " check Run all quality checks (vet, staticcheck, fieldalignment, tests)"
|
||||
@echo " coverage Generate test coverage report"
|
||||
@echo " coverage-html Generate and open HTML coverage report"
|
||||
@echo " bench Run benchmarks"
|
||||
@echo " fmt Format code with gofmt"
|
||||
@echo " tidy Tidy and verify go.mod"
|
||||
@echo " clean Clean build artifacts and caches"
|
||||
@echo " install-tools Install required development tools"
|
||||
@echo " run-example Run the example server"
|
||||
@echo ""
|
||||
|
||||
# Install development tools
|
||||
install-tools:
|
||||
@echo "Installing development tools..."
|
||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
|
||||
@echo "Tools installed successfully!"
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
go test -v ./...
|
||||
|
||||
# Run tests with race detector
|
||||
test-race:
|
||||
@echo "Running tests with race detector..."
|
||||
go test -v -race ./...
|
||||
|
||||
# Run go vet
|
||||
vet:
|
||||
@echo "Running go vet..."
|
||||
go vet ./...
|
||||
|
||||
# Run staticcheck
|
||||
staticcheck:
|
||||
@echo "Running staticcheck..."
|
||||
@command -v staticcheck >/dev/null 2>&1 || { echo "staticcheck not found. Run 'make install-tools'"; exit 1; }
|
||||
staticcheck ./...
|
||||
|
||||
# Check field alignment
|
||||
fieldalignment:
|
||||
@echo "Checking field alignment..."
|
||||
@command -v fieldalignment >/dev/null 2>&1 || { echo "fieldalignment not found. Run 'make install-tools'"; exit 1; }
|
||||
@fieldalignment ./... 2>&1 | tee /tmp/fieldalignment.txt || true
|
||||
@if grep -q ":" /tmp/fieldalignment.txt; then \
|
||||
echo ""; \
|
||||
echo "⚠️ Field alignment issues found."; \
|
||||
echo "Run 'make fieldalignment-fix' to automatically fix them."; \
|
||||
exit 1; \
|
||||
else \
|
||||
echo "✅ No field alignment issues found."; \
|
||||
fi
|
||||
|
||||
# Fix field alignment issues
|
||||
fieldalignment-fix:
|
||||
@echo "Fixing field alignment issues..."
|
||||
@command -v fieldalignment >/dev/null 2>&1 || { echo "fieldalignment not found. Run 'make install-tools'"; exit 1; }
|
||||
fieldalignment -fix ./...
|
||||
@echo "Field alignment issues fixed!"
|
||||
|
||||
# Run all quality checks
|
||||
check: vet staticcheck test-race
|
||||
@echo ""
|
||||
@echo "✅ All checks passed!"
|
||||
|
||||
# Generate test coverage
|
||||
coverage:
|
||||
@echo "Generating coverage report..."
|
||||
go test -coverprofile=coverage.out -covermode=atomic ./...
|
||||
go tool cover -func=coverage.out
|
||||
@echo ""
|
||||
@echo "Total coverage:"
|
||||
@go tool cover -func=coverage.out | grep total | awk '{print $$3}'
|
||||
|
||||
# Generate HTML coverage report
|
||||
coverage-html: coverage
|
||||
@echo "Generating HTML coverage report..."
|
||||
go tool cover -html=coverage.out -o coverage.html
|
||||
@echo "Opening coverage report in browser..."
|
||||
@command -v open >/dev/null 2>&1 && open coverage.html || \
|
||||
command -v xdg-open >/dev/null 2>&1 && xdg-open coverage.html || \
|
||||
echo "Please open coverage.html in your browser"
|
||||
|
||||
# Run benchmarks
|
||||
bench:
|
||||
@echo "Running benchmarks..."
|
||||
go test -bench=. -benchmem ./... -run=^#
|
||||
|
||||
# Format code
|
||||
fmt:
|
||||
@echo "Formatting code..."
|
||||
gofmt -s -w .
|
||||
@echo "Code formatted!"
|
||||
|
||||
# Tidy go.mod
|
||||
tidy:
|
||||
@echo "Tidying go.mod..."
|
||||
go mod tidy
|
||||
go mod verify
|
||||
@echo "go.mod tidied!"
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
go clean -cache -testcache -modcache
|
||||
rm -f coverage.out coverage.html
|
||||
@echo "Clean complete!"
|
||||
|
||||
# Run example server
|
||||
run-example:
|
||||
@echo "Starting example server..."
|
||||
cd example && go run main.go
|
||||
Reference in New Issue
Block a user