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:
158
check.sh
Executable file
158
check.sh
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_step() {
|
||||
echo -e "${BLUE}==>${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
# Check if required tools are installed
|
||||
check_tools() {
|
||||
local missing_tools=()
|
||||
|
||||
if ! command -v staticcheck &> /dev/null; then
|
||||
missing_tools+=("staticcheck")
|
||||
fi
|
||||
|
||||
if ! command -v fieldalignment &> /dev/null; then
|
||||
missing_tools+=("fieldalignment")
|
||||
fi
|
||||
|
||||
if [ ${#missing_tools[@]} -ne 0 ]; then
|
||||
print_warning "Missing tools: ${missing_tools[*]}"
|
||||
echo "Install them with: make install-tools"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Track overall status
|
||||
FAILED=0
|
||||
|
||||
echo ""
|
||||
echo "======================================"
|
||||
echo " Mux - Code Quality Checks"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
|
||||
check_tools
|
||||
|
||||
# Step 1: go vet
|
||||
print_step "Running go vet..."
|
||||
if go vet ./... 2>&1; then
|
||||
print_success "go vet passed"
|
||||
else
|
||||
print_error "go vet failed"
|
||||
FAILED=1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 2: staticcheck (if available)
|
||||
if command -v staticcheck &> /dev/null; then
|
||||
print_step "Running staticcheck..."
|
||||
if staticcheck ./... 2>&1; then
|
||||
print_success "staticcheck passed"
|
||||
else
|
||||
print_error "staticcheck failed"
|
||||
FAILED=1
|
||||
fi
|
||||
echo ""
|
||||
else
|
||||
print_warning "staticcheck not installed, skipping"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Step 3: fieldalignment (if available)
|
||||
if command -v fieldalignment &> /dev/null; then
|
||||
print_step "Checking field alignment..."
|
||||
ALIGNMENT_OUTPUT=$(fieldalignment ./... 2>&1 || true)
|
||||
if echo "$ALIGNMENT_OUTPUT" | grep -q ":"; then
|
||||
print_error "Field alignment issues found:"
|
||||
echo "$ALIGNMENT_OUTPUT"
|
||||
echo ""
|
||||
echo "Run 'make fieldalignment-fix' or 'fieldalignment -fix ./...' to fix automatically"
|
||||
FAILED=1
|
||||
else
|
||||
print_success "No field alignment issues found"
|
||||
fi
|
||||
echo ""
|
||||
else
|
||||
print_warning "fieldalignment not installed, skipping"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Step 4: Run tests
|
||||
print_step "Running tests..."
|
||||
if go test -v ./...; then
|
||||
print_success "All tests passed"
|
||||
else
|
||||
print_error "Tests failed"
|
||||
FAILED=1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 5: Run tests with race detector
|
||||
print_step "Running tests with race detector..."
|
||||
if go test -race ./... > /dev/null 2>&1; then
|
||||
print_success "Race detector passed"
|
||||
else
|
||||
print_error "Race detector found issues"
|
||||
FAILED=1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 6: Check formatting
|
||||
print_step "Checking code formatting..."
|
||||
UNFORMATTED=$(gofmt -l . 2>&1 || true)
|
||||
if [ -z "$UNFORMATTED" ]; then
|
||||
print_success "Code is properly formatted"
|
||||
else
|
||||
print_error "Code is not formatted properly:"
|
||||
echo "$UNFORMATTED"
|
||||
echo ""
|
||||
echo "Run 'make fmt' or 'gofmt -w .' to fix formatting"
|
||||
FAILED=1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 7: Check go.mod
|
||||
print_step "Checking go.mod..."
|
||||
if go mod tidy -diff > /dev/null 2>&1; then
|
||||
print_success "go.mod is tidy"
|
||||
else
|
||||
print_warning "go.mod needs tidying"
|
||||
echo "Run 'make tidy' or 'go mod tidy' to fix"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Final result
|
||||
echo "======================================"
|
||||
if [ $FAILED -eq 0 ]; then
|
||||
print_success "All checks passed! 🎉"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
exit 0
|
||||
else
|
||||
print_error "Some checks failed"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user