Prerequisites
Before you begin, ensure you have the following installed:| Tool | Required version | Check command |
|---|---|---|
| Go | 1.23.1 or higher | go version |
| PostgreSQL | 15 or higher | psql --version |
| Docker | Latest | docker --version |
| Git | Latest | git --version |
| Atlas | Latest | atlas version |
| sqlc | Latest | sqlc version |
Step 1: Clone the repository
Step 2: Install PostgreSQL
macOS (using Homebrew)
Ubuntu/Debian
Windows
Download and install from PostgreSQL official website.Verify installation
Step 3: Create database
Step 4: Set up environment variables
Create a.env file in the project root:
.env with your configuration:
Getting a Google Geocoding API key
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Geocoding API
- Go to Credentials → Create Credentials → API Key
- Copy the API key and add it to your
.envfile
Step 5: Install development tools
Install Atlas
Install sqlc
Install Lefthook (Git hooks)
Step 6: Make scripts executable
scripts/ directory executable.
Step 7: Run database migrations
Apply all migrations using the provided script:DATABASE_URL from your .env file. Alternatively, pass the URL directly:
Verify migrations
Step 8: Generate database code
The project uses sqlc to generate type-safe Go code from SQL queries.database/generated_models/.
Step 9: Install Go dependencies
Step 10: Start the server
Step 11: Verify the server is running
Test root endpoint
Test health endpoint
Step 12: Create an API key for testing
Connect to the database and insert a test API key:Step 13: Test the geocoding endpoint
Troubleshooting
Error: “could not ping the database”
Cause: PostgreSQL is not running or connection details are incorrect. Fix:Error: “missing required environment variables”
Cause:.env file is missing or incomplete.
Fix: Ensure all required variables are set in .env:
RDS_USERNAMERDS_PASSWORDRDS_HOSTNAMERDS_PORTRDS_DBNAME
Error: “GOOGLE_GEOCODING_API_KEY is required”
Cause: Google API key is not set or invalid. Fix:- Get a valid API key from Google Cloud Console
- Add it to
.envfile - Restart the server