A simple RESTful To-Do List API built with Go, using MySQL for persistence.
- CRUD operations for tasks
- MySQL database integration
- RESTful API design
- Docker & Docker Compose support
- Environment variable configuration
cmd/server/main.go # Application entrypoint
internal/db/db.go # Database connection logic
internal/routes/routes.go # API route definitions
internal/task/model.go # Task model definition
internal/task/handlers.go # Task handler functions
- Docker
- Docker Compose
- (Optional) Go for local development
Copy .env.example to .env and adjust as needed:
cp .env.example .envStart the API and MySQL database:
docker-compose up --build- API: http://localhost:8080
- MySQL: localhost:3306 (see
.envfor credentials)
- Ensure MySQL is running and matches your
.envconfig. - Build and run the server:
go build -o server ./cmd/server ./server
| Method | Endpoint | Description |
|---|---|---|
| GET | api/v1/tasks | List all tasks |
| POST | api/v1/tasks | Create a new task |
| GET | api/v1/tasks/{id} | Get a task by ID |
| PUT | api/v1/tasks/{id} | Update a task |
| DELETE | api/v1/tasks/{id} | Delete a task |
- MySQL database is automatically created by Docker Compose.
- Data is persisted in a Docker volume (
db_data).
- Code is organized using Go modules.
- Main application entry:
cmd/server/main.go - Business logic and handlers:
internal/
- Format code:
go fmt ./... - Tidy modules:
go mod tidy - Run tests:
go test ./...