Create the repo, Makefile, lint config and docker-compose
Create the backend module with the cmd/ and internal/ layout, a Makefile with lint, test, run, up and down targets, a golangci-lint config, and a docker-compose file for MySQL and Redis.
Objective
Set up the backend project in your clone of the public zomato-prep repository so future exercises have a consistent development environment. You will add the project automation, lint configuration, and local service definitions without writing any Go code.
By the end:
- The backend has a
Makefilewith commands for linting, testing, running, and managing local services. - The project has a
golangci-lintv2 configuration with explicitly selected linters and formatters. - Docker Compose can start MySQL 8.4 and Redis 7.
- Both services report healthy status through their healthchecks.
- The project commands run from
backend/.
Deliverables
-
backend/Makefile: Add the project commands:lint: Rungolangci-lint run.test: Run the course test runner usinggo run ./tools/zt test $(W).unit: Run Go unit tests with the race detector.run: Start the API usinggo run ./cmd/api.up: Start Docker Compose services in the background.down: Stop Docker Compose services.
Declare all targets as
.PHONY. The test target must allow an optional exercise selector:make test W=1B2runs one exercise, whilemake testruns all exercises. -
backend/.golangci.yml: Configure golangci-lint v2 with:version: "2"andlinters.default: none.- Enabled linters:
errcheck,govetwithshadow,ineffassign,staticcheck,unused,errorlint, andgosec, excludingG404. - Enabled formatters:
gofumptandgoimports. goimportslocal prefix:github.com/yashdagar/zomato-prep.
-
backend/docker-compose.yml: Define two services:- MySQL: Use
mysql:8.4, readMYSQL_ROOT_PASSWORDfrom the environment withdevas the default, create thezomatodatabase, publish port3306, mount a named volume for persistent data, and configure amysqladmin pinghealthcheck using the same root password. - Redis: Use
redis:7-alpine, publish port6379, and configure aredis-cli pinghealthcheck.
- MySQL: Use
No Go source files are required in this exercise. The starter repository already contains the tests, the tools/zt test runner, and the Go module for module github.com/yashdagar/zomato-prep/backend. You will add cmd/ and internal/ directories as later exercises need them.
Requirements
Constraints
-
Work inside the
backend/directory. Run all commands in this exercise from there. -
Use the pinned image versions
mysql:8.4andredis:7-alpine. Do not uselatest. -
Use healthchecks for both services so dependent tools can determine when they are ready.
-
Use a named Docker volume for MySQL data.
-
Use the same
MYSQL_ROOT_PASSWORDvariable for the MySQL service and its healthcheck. -
Keep the Makefile recipe indentation as tabs, not spaces.
-
Declare every Makefile target as
.PHONY. -
Do not introduce credentials beyond the local development defaults. The default password
devis only for local development. -
Do not write Go code or rewrite the provided test runner.
-
make lintrequires golangci-lint v2 to be installed. Install it using Homebrew:bash brew install golangci-lintAlternatively, use the official golangci-lint installation script from its documentation.
-
Docker must be running before you execute the Compose commands.
Acceptance criteria
Run the following commands from backend/:
go version
make up
docker compose ps
make lint
make test
make downEach command has an expected result:
go version: Prints the installed Go version. The project uses Go 1.25, so use a compatible Go toolchain.make up: Starts the MySQL and Redis containers in detached mode. Docker Compose reports that the services have been started.docker compose ps: Shows both services running and their health status ashealthy. If they are still starting, wait briefly and check again.make lint: Runs golangci-lint v2 without a configuration error. There are no application Go packages to lint yet, so the command must not fail because of the empty project or the linter configuration.make test: Runs the course test runner. It reports that the exercise steps have not been written yet. This is expected because this exercise creates the development environment, not the Go implementation.make down: Stops and removes the Compose containers and network. The named MySQL volume remains available for the nextmake up.
The complete command sequence is:
cd backend
go version
make up
docker compose ps
make lint
make test
make downRun the commands in order. Do not run make lint or make test from the repository root.
The reference solution passes every check for this exercise. Try the hints first; reading the answer before you have struggled with the problem teaches much less.
Project setup
3 items
- 1.1The Go toolchain, modules and packagesnot completed
- 1.2Makefile, golangci-lint and Docker Composenot completed
- 1.3Create the repo, Makefile, lint config and docker-composenot completed
Up next · Module 2 · 5 items · about 2 h 30 min
Implementation
Run locally
Write the code in your editor inside zomato-prep, then work through this list.
backend/go.moddeclares the modulegithub.com/yashdagar/zomato-prep/backend.make upstarts MySQL and Redis anddocker compose psshows both healthy.make lintruns golangci-lint and exits cleanly on the empty project.make testrunsgo test ./...without errors.make downstops the containers.
Commands
cd backend && go versioncd backend && make upcd backend && docker compose pscd backend && make lintThis exercise has no Go test. The commands above are the check: when each one shows what the list says, the exercise is done.