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"
}