Prerequisites
Before building BookMe, ensure you have:- Go 1.22+ installed
- PostgreSQL 14+ running
- Make installed (optional but recommended)
- Environment variables configured (see
.env.example)
The project uses Go 1.25.7 as specified in
go.mod:3, but Go 1.22+ is the minimum requirement.Quick Start
Install Dependencies
Download and install all Go dependencies:This runs:
go mod download- Downloads dependenciesgo mod tidy- Cleans up unused dependencies
Set Up Environment
Build Commands
Available Make Targets
TheMakefile provides convenient commands for common tasks:
Detailed Build Process
Building the Binary
The build command is defined inMakefile:12-15:
bin/book-me. Run it directly:
Running in Development
Standard Run
go run ./cmd/server, which compiles and runs the application.
Hot Reload Development
For automatic reloading on file changes:-
Install Air:
-
Run with hot reload:
Code Generation
SQLC - Type-Safe Database Queries
BookMe uses SQLC to generate Go code from SQL queries.When to Regenerate
Runmake sqlc after:
- Adding new SQL queries in
sql/queries/ - Modifying existing queries
- Changing database schema in
sql/schema/
SQLC Workflow
Generated files are committed to version control. This ensures consistent builds without requiring SQLC to be installed in production environments.
Code Formatting
Format Go Code
go fmt ./... to format all Go files according to standard conventions.
Linting
The project usesgolangci-lint with strict rules defined in .golangci.yml:1-58.
Run the linter:
Enabled Linters
The configuration includes:- errcheck - Checks for unchecked errors
- govet - Reports suspicious constructs
- staticcheck - Advanced analysis
- gosec - Security issues
- revive - Style and correctness
- bodyclose - HTTP response body leaks
- errorlint - Proper error handling
- exhaustive - Missing switch cases
Build Configuration
Binary Output
Build configuration fromMakefile:14:
Application Entry Point
The main function is incmd/server/main.go:22-26:
run() function handles:
- Configuration loading
- Logger initialization
- Database connection
- API setup
- HTTP server start
- Graceful shutdown
Environment-Specific Builds
Development Build
No special flags needed:Production Build
Optimize binary size and disable debug info:-s- Omit symbol table-w- Omit DWARF debug info
Cross-Compilation
Build for different platforms:Dependencies
Core Dependencies
Fromgo.mod:5-18:
| Package | Purpose |
|---|---|
github.com/golang-jwt/jwt/v5 | JWT authentication |
github.com/lib/pq | PostgreSQL driver |
github.com/joho/godotenv | Environment variables |
github.com/go-playground/validator/v10 | Input validation |
github.com/wneessen/go-mail | Email sending |
golang.org/x/oauth2 | OAuth2 client |
google.golang.org/api | Google Calendar API |
golang.org/x/time | Rate limiting |
github.com/hashicorp/go-retryablehttp | Retry logic |
github.com/gorilla/sessions | Session management |
Installing Dependencies
All dependencies are defined ingo.mod. Install with:
Troubleshooting
Common Build Issues
Build fails with 'cmd/api not found'
Build fails with 'cmd/api not found'
The Makefile references the wrong path. Update
Makefile:14:Database connection errors
Database connection errors
Check:
- PostgreSQL is running
DB_URLin.envis correct- Database exists and migrations are applied
SQLC generation fails
SQLC generation fails
Ensure SQLC is installed:Verify
sqlc.yaml configuration is correct.Missing environment variables
Missing environment variables
The server will fail if required env vars are missing. Check
internal/config/config.go for required fields.Copy and configure:Docker Build (Optional)
While not included in the repository, you can create a Dockerfile:Next Steps
- Testing Guide - Learn about the test suite
- Project Structure - Understand the codebase
- Contributing - Submit your first PR