Backend local setup
The backend won’t start without a database and a Firebase project, so this page sets up both. You’ll need Go 1.27.3 or newer (earlier 1.27 releases are missing security fixes), Git, Docker Desktop, and a Firebase service-account key saved outside the repository.
-
Clone the repository.
Terminal window git clone https://github.com/Hostel-Hive/hostelhive-backend.gitcd hostelhive-backend -
Create the PostgreSQL container. You only do this once.
Terminal window $env:POSTGRES_PASSWORD = 'local-dev-only'docker run --name hostelhive-postgres -d -p 127.0.0.1:15433:5432 -e POSTGRES_PASSWORD -e POSTGRES_USER=hostelhive -e POSTGRES_DB=hostelhive postgres:16-alpinedocker exec hostelhive-postgres pg_isready -U hostelhive -d hostelhiveWait for
accepting connections. On later days,docker start hostelhive-postgresis enough. -
Copy the example settings and open the copy.
Terminal window Copy-Item .env.example .env.localnotepad .env.localThese three lines are the ones that matter for a first run:
DATABASE_URL=postgres://hostelhive:local-dev-only@127.0.0.1:15433/hostelhive?sslmode=disableFIREBASE_PROJECT_ID=your-firebase-project-idGOOGLE_APPLICATION_CREDENTIALS=C:/private/hostelhive-service-account.jsonGit ignores
.env.local. Every other setting is described on Configuration. -
Install the migration tool, create the tables and start the server.
Terminal window .\scripts\install-migrate.ps1.\scripts\dev.ps1 -Migrate
Starting it day to day
Section titled “Starting it day to day”.\scripts\dev.ps1The script reads .env.local, checks that the required values and the credentials file are there, starts the Postgres container, waits for it, and runs go run ./cmd/server. Ctrl+C stops the server and leaves the database running.
It takes a few flags. -Check validates your settings without starting anything. -Migrate applies pending migrations first. -SkipDatabase skips Docker when DATABASE_URL points at a hosted database. -EnvFile and -DatabaseContainer let you use a different settings file or container name.
Checking it works
Section titled “Checking it works”curl.exe -i http://127.0.0.1:18080/healthcurl.exe -i http://127.0.0.1:18080/readycurl.exe -i http://127.0.0.1:18080/api/v1/me/health returns 200 as long as the process is up. /ready also pings the database and returns 503 if it can’t reach it. /api/v1/me should return 401, because you didn’t send a token. The interactive API explorer is at http://127.0.0.1:18080/docs/.
Running without the script
Section titled “Running without the script”The Go binary never reads .env files. It only sees environment variables, so set them yourself:
$env:DATABASE_URL = 'postgres://hostelhive:local-dev-only@127.0.0.1:15433/hostelhive?sslmode=disable'$env:FIREBASE_PROJECT_ID = 'your-firebase-project-id'$env:GOOGLE_APPLICATION_CREDENTIALS = 'C:/private/hostelhive-service-account.json'$env:HTTP_ADDR = '127.0.0.1:18080'go run ./cmd/serverexport DATABASE_URL='postgres://hostelhive:local-dev-only@127.0.0.1:15433/hostelhive?sslmode=disable'export FIREBASE_PROJECT_ID='your-firebase-project-id'export GOOGLE_APPLICATION_CREDENTIALS="$HOME/private/hostelhive-service-account.json"export HTTP_ADDR='127.0.0.1:18080'go run ./cmd/serverTo build a binary instead, run go build -o ./bin/hostelhive-server ./cmd/server (add .exe on Windows).
Before you open a pull request
Section titled “Before you open a pull request”gofmt -l ./cmd ./internal ./testsgo vet ./...go test -count=1 -timeout=45s ./...go build ./....\scripts\test-migrations.ps1gofmt -l should print nothing. The scripts/test-*.ps1 suites each spin up a throwaway Postgres container, run against it, and delete it, so they never touch your development data.