A basic Todo application built with Go, Gin framework, and MongoDB featuring both REST API and web interface
- RESTful API - Clean and organized REST endpoints
- Official MongoDB Driver Integration - Persistent data storage with efficient queries
- Gin Framework - Fast HTTP web framework with middleware support
- JSON API - Standard JSON responses for all endpoints
- Error Handling - Error handling and validation
- Context Management - Proper timeout handling for database operations
- Interactive UI - Dynamic web interface with real-time updates
- Responsive Design - Mobile-friendly responsive layout
- AJAX Operations - Smooth user experience without page reloads
- Task Management - Add, delete, and view tasks seamlessly
- Visual Feedback - Intuitive user interface with Font Awesome icons
todo-golang/
├── 📁 controllers/ # Business logic and request handlers
│ ├── task.go # Task controller with CRUD operations
│ └── task_test.go # Controller unit tests
├── 📁 models/ # Data models and structures
│ ├── task.go # Task and ViewTask model definitions
│ └── task_test.go # Model unit tests
├── 📁 public/ # Static assets
│ ├── 📁 css/
│ │ └── style.css # Application styles
│ ├── 📁 img/
│ │ └── *.ico # Favicon and images
│ └── 📁 js/
│ └── index.js # Frontend JavaScript logic
├── 📁 templates/ # HTML templates
│ └── index.gohtml # Main application template
├── 📄 main.go # Application entry point and server setup
├── 📄 go.mod # Go module dependencies
├── 📄 go.sum # Go module checksums
├── 📄 integration_test.go # Integration tests
├── 📄 Dockerfile # Docker container configuration
├── 📄 docker-compose.yml # Docker Compose setup
├── 📄 Makefile # Build automation
├── 📄 .air.toml # Live reload configuration
├── 📄 .env # Environment variables
└── 📄 init-mongo.js # MongoDB initialization script
Make sure you have the following installed on your system:
- Docker (includes Docker Compose) - Install Docker
- Git - Install Git
-
Clone the repository
git clone <your-repository-url> cd todo-golang
-
Start the application with Docker Compose
docker-compose up --build
-
Access the application
- Web Interface: http://localhost:8080/view/tasks
- API Base URL: http://localhost:8080/api
# Build and start all services
docker-compose up --build
# Run in background (detached mode)
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# Rebuild and restart
docker-compose down && docker-compose up --buildhttp://localhost:8080/api
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
GET |
/tasks |
Retrieve all tasks | - | Array of tasks |
POST |
/task |
Create a new task | {"description": "string"} |
Created task object |
DELETE |
/task/:id |
Delete specific task | - | Success message |
DELETE |
/tasks |
Delete all tasks | - | Success message with count |
| Method | Endpoint | Description |
|---|---|---|
GET |
/view/tasks |
Display tasks in HTML template |
curl -X POST http://localhost:8080/api/task \
-H "Content-Type: application/json" \
-d '{"description": "Learn Go programming"}'Response:
{
"id": "507f1f77bcf86cd799439011",
"description": "Learn Go programming"
}curl http://localhost:8080/api/tasksResponse:
[
{
"id": "507f1f77bcf86cd799439011",
"description": "Learn Go programming"
},
{
"id": "507f1f77bcf86cd799439012",
"description": "Build a REST API"
}
]curl -X DELETE http://localhost:8080/api/task/507f1f77bcf86cd799439011Response:
{
"message": "Task deleted successfully"
}curl -X DELETE http://localhost:8080/api/tasksResponse:
{
"message": "All tasks deleted successfully",
"deletedCount": 5
}go test ./...go test -tags=integrationgo test -cover ./...- Navigate to http://localhost:8080/view/tasks
- Add new tasks using the input field
- Delete individual tasks using the trash icon
- Clear all tasks using the "Clear all" button
- Go (v1.25) - Modern programming language
- Gin - HTTP web framework
- MongoDB - NoSQL database
- MongoDB Go Driver (v2.3.0) - Official MongoDB driver
- HTML5 - Semantic markup with Go templates
- CSS3 - Modern styling with Flexbox
- Vanilla JavaScript - Interactive functionality with Fetch API
- Air - Live reload for Go apps
- Docker - Containerization
- Make - Build automation
MONGODB_URI- MongoDB connection string (default: detected from environment)
{
"_id": "ObjectId",
"description": "string"
}