Complete guide for setting up a local development environment for LDAP Manager.
Install these tools before beginning development:
# Check current Go version
go version
# Should show 1.23.0 or higherInstallation:
- Linux/macOS: Use official installer from https://golang.org/dl/
- Windows: Download and run MSI installer
- Package Managers:
- Ubuntu:
sudo apt install golang-1.23 - macOS:
brew install go
- Ubuntu:
# Check current Node.js version
node --version
# Should show v16.0.0 or higherInstallation:
- Official: Download from https://nodejs.org/
- nvm (recommended):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash nvm install 16 nvm use 16
Corepack for PNPM:
# Enable corepack (comes with Node.js 16+)
npm install -g corepack
corepack enable
# Verify PNPM is available
pnpm --versionRequired for type-safe HTML template compilation:
# Install templ
go install github.com/a-h/templ/cmd/templ@latest
# Verify installation
templ --versionThese tools enhance the development experience:
# Air for hot reloading
go install github.com/cosmtrek/air@latest
# pre-commit for git hooks
pip install pre-commit# Clone the repository
git clone https://github.com/netresearch/ldap-manager.git
cd ldap-manager
# Install all dependencies and development tools
make setup
# This runs:
# - make setup-go (Go dependencies)
# - make setup-node (Node.js dependencies)
# - make setup-tools (Development tools)Create your local environment configuration:
# Copy example configuration
cp .env.example .env.local
# Edit with your LDAP settings
nano .env.localExample .env.local for development:
# LDAP Configuration
LDAP_SERVER=ldap://localhost:389
LDAP_BASE_DN=DC=dev,DC=local
LDAP_READONLY_USER=cn=admin,dc=dev,dc=local
LDAP_READONLY_PASSWORD=admin
LDAP_IS_AD=false
# Development Settings
LOG_LEVEL=debug
PERSIST_SESSIONS=true
SESSION_PATH=dev-session.bbolt
SESSION_DURATION=8h
# Optional: Custom listen address
LISTEN_ADDR=:3000Install pre-commit hooks for code quality:
make setup-hooks
# This installs hooks for:
# - Go formatting (gofumpt)
# - Import organization (goimports)
# - Markdown linting
# - Secret detectionThe recommended way to start development:
# Start development server with hot reload
make devThis starts multiple concurrent processes:
- Go server with Air hot reloading
- CSS compilation with TailwindCSS watch mode
- Template compilation with templ watch mode
Alternative PNPM commands:
# Development with hot reload
pnpm dev
# Individual processes
pnpm css:dev # Watch CSS changes
pnpm templ:dev # Watch template changes
pnpm go:dev # Go server with hot reloadWhen make dev is running:
- Automatic Rebuilds: Changes to Go, CSS, or templates trigger rebuilds
- Browser Refresh: Assets are automatically rebuilt and served
- Debug Logging: Verbose logging enabled by default
- Long Sessions: 8-hour session duration for convenience
# Build application with assets
make build
# This creates:
# - ./ldap-manager (executable binary)
# - Compiled CSS in internal/web/static/
# - Compiled templates as Go files# Build only CSS and templates
make build-assets
# Individual asset builds
pnpm css:build # Build TailwindCSS
pnpm templ:build # Build templ templates# Remove all build artifacts
make clean
# Clean specific artifacts
pnpm clean:css # Remove CSS builds
pnpm clean:templ # Remove template builds# Run complete test suite with coverage
make test
# Quick tests without coverage
make test-quick
# Tests without race detection (faster)
make test-short
# Performance benchmarks
make benchmarkTest Output:
- Coverage reports in
coverage-reports/coverage.html - Test results with pass/fail status
- Benchmark performance metrics
# Run all quality checks (linting + tests)
make check
# Individual quality tools
make lint # All linters
make lint-go # Go-specific linters
make lint-format # Format checking
make lint-security # Security scanningLinting Tools Used:
- golangci-lint: Comprehensive Go linting (30+ linters)
- govulncheck: Security vulnerability scanning
- gocyclo: Cyclomatic complexity analysis
- staticcheck: Advanced static analysis
# Automatically fix code formatting
make fix
# This runs:
# - gofumpt (Go formatting)
# - goimports (import organization)
# - Prettier (CSS/JS formatting)ldap-manager/
├── cmd/ # Application entry points
├── internal/ # Private application code
│ ├── web/ # HTTP handlers and middleware
│ ├── ldap_cache/ # LDAP connection and caching
│ ├── options/ # Configuration management
│ └── build.go # Build information injection
├── docs/ # Documentation
├── scripts/ # Build and utility scripts
├── coverage-reports/ # Test coverage output
└── dist/ # Release binaries
Makefile: Development automation (40+ targets).air.toml: Hot reload configuration.golangci.yml: Linter configurationpackage.json: Node.js dependencies and scriptstailwind.config.js: TailwindCSS configuration.env.example: Configuration template
The Makefile provides comprehensive automation:
make setup- Complete development environment setupmake setup-go- Go dependencies onlymake setup-node- Node.js dependencies onlymake setup-tools- Development tools installation
make build- Build application with assetsmake build-assets- Build CSS and templates onlymake build-release- Multi-platform release builds
make test- Full test suite with coveragemake benchmark- Performance benchmarksmake lint- All linting toolsmake check- Quality gate (lint + test)
make dev- Development server with hot reloadmake serve- Run built applicationmake clean- Remove build artifacts
make help- List all available targetsmake info- Show build environment information
Recommended extensions:
{
"recommendations": ["golang.go", "a-h.templ", "bradlc.vscode-tailwindcss", "esbenp.prettier-vscode"]
}Settings (.vscode/settings.json):
{
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.formatTool": "gofumpt",
"go.lintTool": "golangci-lint",
"tailwindCSS.includeLanguages": {
"templ": "html"
},
"[templ]": {
"editor.defaultFormatter": "a-h.templ"
}
}- Install Go plugin
- Configure Go SDK (1.23+)
- Set gofumpt as formatter
- Enable golangci-lint integration
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch LDAP Manager",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/ldap-manager",
"env": {
"LOG_LEVEL": "debug"
},
"args": []
}
]
}# Debug with delve
go install github.com/go-delve/delve/cmd/dlv@latest
dlv debug cmd/ldap-manager/main.go
# Debug tests
go test -v ./internal/web -run TestSpecificFunctionTests are organized by package:
internal/
├── web/
│ ├── handlers.go
│ ├── handlers_test.go # Unit tests
│ └── integration_test.go # Integration tests
├── ldap_cache/
│ ├── manager.go
│ ├── manager_test.go
│ └── benchmark_test.go # Performance tests
└── options/
├── options.go
└── options_test.go
- Test individual functions and methods
- Use mocking for external dependencies
- Fast execution, no external services
- Test component interactions
- May use test LDAP server
- Slower execution, more realistic scenarios
- Performance regression detection
- Memory allocation profiling
- Execution time measurement
- Minimum: 80% coverage (enforced by CI)
- Target: 90%+ for critical paths
- Reports: HTML coverage reports generated
For integration testing without external dependencies:
# Start test LDAP server (Docker)
docker run -d --name test-ldap \
-p 389:389 \
-e LDAP_ORGANISATION="Test Org" \
-e LDAP_DOMAIN="test.local" \
-e LDAP_ADMIN_PASSWORD="admin" \
osixia/openldap:latest
# Configure tests to use local LDAP
export LDAP_SERVER=ldap://localhost:389
export LDAP_BASE_DN=dc=test,dc=local
export LDAP_READONLY_USER=cn=admin,dc=test,dc=local
export LDAP_READONLY_PASSWORD=admin# Parallel builds
make -j$(nproc) build
# Cache Go builds
export GOCACHE=$HOME/.cache/go-build
export GOMODCACHE=$HOME/go/pkg/mod# Skip slower checks during development
make test-quick # Skip coverage
make test-short # Skip race detection
# Selective testing
go test ./internal/web -run TestHandlers# CPU profiling
go test -cpuprofile=cpu.prof -bench=.
# Memory profiling
go test -memprofile=mem.prof -bench=.
# View profiles
go tool pprof cpu.prof# Reinstall templ
go install github.com/a-h/templ/cmd/templ@latest
# Add Go bin to PATH
export PATH=$PATH:$(go env GOPATH)/bin# Enable corepack
npm install -g corepack
corepack enable
# Or install PNPM directly
npm install -g pnpm# Clean and rebuild
make clean
make setup
make build
# Check Go version
go version # Should be 1.23+
# Check Node version
node --version # Should be 16+# Run specific test with verbose output
go test -v ./internal/web -run TestFailingTest
# Check for race conditions
go test -race ./...
# Update test dependencies
go mod tidy# Test LDAP connectivity
ldapsearch -H ldap://localhost:389 -x -s base
# Check Docker LDAP server
docker logs test-ldap
# Verify configuration
echo $LDAP_SERVER $LDAP_BASE_DN- Explore the Codebase: Start with
internal/web/handlers.go - Make Your First Change: Try modifying a template in
internal/web/ - Run Tests: Ensure your changes don't break existing functionality
- Review Architecture: See Architecture Guide
- Contribute: Follow Contributing Guidelines