Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# golangci-lint configuration for version 2.x
# See https://golangci-lint.run/usage/configuration/
version: 2

run:
timeout: 5m
tests: true
modules-download-mode: readonly

linters:
# Enable most linters for comprehensive code quality checks
enable:
# Default linters (always enabled):
# errcheck, govet, ineffassign, staticcheck, unused

# Style & best practices
- misspell # Find commonly misspelled words
- revive # Fast, configurable linter
- gofmt # Check code formatting
- goimports # Check import formatting
- godot # Check if comments end in a period
- dupword # Check for duplicate words

# Security
- gosec # Inspect code for security problems

# Bugs & correctness
- bodyclose # Check HTTP response body is closed
- contextcheck # Check context usage
- errorlint # Check error wrapping
- durationcheck # Check duration multiplication
- copyloopvar # Check loop variable copying

# Code quality
- gocritic # Meta-linter with many checks
- goconst # Find repeated strings
- gocyclo # Check cyclomatic complexity
- funlen # Check function length
- nestif # Check deeply nested if statements

# Code organization
- decorder # Check declaration order
- grouper # Analyze expression groups

# Simplification
- unconvert # Remove unnecessary type conversions
- unparam # Find unused function parameters

linters-settings:
errcheck:
check-blank: false
check-type-assertions: false

govet:
settings:
shadow:
strict: false

staticcheck:
checks: ["all"]

revive:
rules:
- name: var-naming
disabled: true
- name: dot-imports
disabled: false

funlen:
lines: 150
statements: 80

gocyclo:
min-complexity: 20

nestif:
min-complexity: 5

gocritic:
enabled-checks:
- appendAssign
- assignOp
- boolExprSimplify
- builtinShadow
- captLocal
- caseOrder
- defaultCaseOrder
- dupArg
- dupBranchBody
- dupCase
- elseif
- emptyFallthrough
- emptyStringTest
- equalFold
- flagDeref
- ifElseChain
- indexAlloc
- methodExprCall
- rangeExprCopy
- rangeValCopy
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlambda
- unnecessaryBlock
- unslice
- valSwap
- weakCond
- wrapperFunc
- yodaStyleExpr

issues:
max-issues-per-linter: 0
max-same-issues: 0

exclude-rules:
# Exclude some linters from running on tests files
- path: _test\.go
linters:
- errcheck
- gosec

output:
formats:
colored-line-number:
path: stdout
print-issued-lines: true
print-linter-name: true
204 changes: 204 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
.PHONY: help test test-unit test-integration test-all test-coverage dynamo-start dynamo-stop dynamo-clean build clean lint fmt vet setup

# Default target
help:
@echo "DynamoDB Utilities - Available Commands"
@echo "========================================"
@echo " make setup - Setup development environment (install dependencies)"
@echo ""
@echo " make test - Run unit tests only"
@echo " make test-unit - Run unit tests only (alias)"
@echo " make test-integration - Run integration tests (requires DynamoDB Local)"
@echo " make test-all - Run all tests with DynamoDB Local"
@echo " make test-coverage - Generate test coverage report"
@echo ""
@echo " make lint - Run all linters (golangci-lint, go fmt, go vet)"
@echo " make fmt - Format code with go fmt"
@echo " make vet - Run go vet"
@echo ""
@echo " make dynamo-start - Start DynamoDB Local in Docker"
@echo " make dynamo-stop - Stop DynamoDB Local"
@echo " make dynamo-clean - Stop and remove DynamoDB Local container"
@echo ""
@echo " make build - Build the application"
@echo " make clean - Clean build artifacts"

# Setup development environment
setup:
@echo "Setting up development environment..."
@echo ""
@echo "Checking dependencies..."
@echo ""

@# Check Go version
@echo "✓ Go version:"
@go version
@echo ""

@# Check Docker
@if command -v docker >/dev/null 2>&1; then \
echo "✓ Docker is installed"; \
docker --version; \
else \
echo "✗ Docker is not installed"; \
echo " Please install Docker: https://docs.docker.com/get-docker/"; \
fi
@echo ""

@# Install/Check golangci-lint
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "✓ golangci-lint is already installed"; \
golangci-lint --version; \
else \
echo "Installing golangci-lint..."; \
if [ "$$(uname)" = "Darwin" ]; then \
if command -v brew >/dev/null 2>&1; then \
brew install golangci-lint; \
else \
echo "Homebrew not found. Installing via curl..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin; \
fi; \
elif [ "$$(uname)" = "Linux" ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin; \
else \
echo "Please install golangci-lint manually: https://golangci-lint.run/usage/install/"; \
fi; \
if command -v golangci-lint >/dev/null 2>&1; then \
echo "✓ golangci-lint installed successfully"; \
fi; \
fi
@echo ""

@# Install Go dependencies
@echo "Installing Go dependencies..."
@go mod download
@go mod tidy
@echo "✓ Go dependencies installed"
@echo ""

@# Verify setup
@echo "Verifying setup..."
@go mod verify
@echo "✓ Go modules verified"
@echo ""

@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "✓ Development environment setup complete!"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo ""
@echo "Next steps:"
@echo " 1. Run 'make build' to build the application"
@echo " 2. Run 'make test' to run unit tests"
@echo " 3. Run 'make lint' to check code quality"
@echo " 4. Run 'make help' to see all available commands"
@echo ""

# Build the application
build:
@echo "Building dynamoutil..."
go build -o bin/dynamoutil .
@echo "Build complete: bin/dynamoutil"

# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
rm -f coverage.out coverage.html
@echo "Clean complete"

# Run unit tests only
test: test-unit

test-unit:
@echo "Running unit tests..."
go test -v -short ./...

# Start DynamoDB Local in Docker
dynamo-start:
@echo "Starting DynamoDB Local..."
@if [ "$$(docker ps -q -f name=dynamodb-local)" ]; then \
echo "DynamoDB Local is already running"; \
else \
docker run -d --name dynamodb-local -p 8000:8000 amazon/dynamodb-local; \
echo "Waiting for DynamoDB Local to start..."; \
sleep 3; \
echo "DynamoDB Local started on http://localhost:8000"; \
fi

# Stop DynamoDB Local
dynamo-stop:
@echo "Stopping DynamoDB Local..."
@docker stop dynamodb-local 2>/dev/null || echo "DynamoDB Local is not running"

# Stop and remove DynamoDB Local container
dynamo-clean:
@echo "Cleaning up DynamoDB Local..."
@docker stop dynamodb-local 2>/dev/null || true
@docker rm dynamodb-local 2>/dev/null || true
@echo "DynamoDB Local cleaned up"

# Run integration tests (requires DynamoDB Local)
test-integration: dynamo-clean dynamo-start
@echo "Running integration tests..."
@sleep 2
@AWS_ACCESS_KEY_ID=testaccesskeyid \
AWS_SECRET_ACCESS_KEY=testsecretaccesskey \
DYNAMODB_ENDPOINT=http://localhost:8000 \
go test -v -tags=integration ./pkg/db; \
TEST_EXIT_CODE=$$?; \
$(MAKE) dynamo-clean; \
exit $$TEST_EXIT_CODE

# Run all tests with DynamoDB Local
test-all: dynamo-start
@echo "Running all tests..."
@sleep 2
DYNAMODB_ENDPOINT=http://localhost:8000 go test -v -tags=integration ./...
@echo ""
@echo "All tests completed!"

# Generate test coverage report
test-coverage: dynamo-start
@echo "Generating test coverage report..."
@sleep 2
DYNAMODB_ENDPOINT=http://localhost:8000 go test -coverprofile=coverage.out -tags=integration ./...
go tool cover -html=coverage.out -o coverage.html
@echo ""
@echo "Coverage report generated: 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 manually"

# Run tests in CI environment
test-ci: dynamo-start
@echo "Running tests in CI mode..."
@sleep 2
DYNAMODB_ENDPOINT=http://localhost:8000 go test -v -tags=integration -coverprofile=coverage.out ./...
go tool cover -func=coverage.out

# Format code with go fmt
fmt:
@echo "Running go fmt..."
@gofmt -l -w .
@echo "Formatting complete"

# Run go vet
vet:
@echo "Running go vet..."
@go vet ./...
@echo "go vet complete"

# Run all linters
lint: fmt vet
@echo "Running golangci-lint..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
echo "Linting complete"; \
else \
echo "⚠️ golangci-lint is not installed"; \
echo "Install with: brew install golangci-lint (macOS)"; \
echo "Or visit: https://golangci-lint.run/usage/install/"; \
echo ""; \
echo "Continuing with go fmt and go vet only..."; \
fi
Loading