A feature-rich command-line task manager built with Go. This project was created as a learning exercise to explore Go's features and best practices. Each component is thoroughly documented with comments to explain the implementation details and Go concepts used.
This project demonstrates several important Go concepts and patterns:
- 📚 Package Organization: How to structure a Go project with multiple packages
- 🔒 Concurrency: Using mutexes for thread-safe operations
- 💾 File I/O: JSON serialization and persistent storage
- 🧪 Testing: Table-driven tests and test coverage
- 🎯 CLI Development: Using cobra for command-line interfaces
- 📝 Documentation: Comprehensive code comments explaining implementation details
- ⚡ Performance: Efficient data structures and algorithms
- 🔧 Error Handling: Proper error handling patterns in Go
- ✨ Add tasks with titles and descriptions
- 📅 Set due dates for tasks
- ⭐ Assign priority levels (high, medium, low)
- 🏷️ Add tags for better organization
- 📋 List tasks with powerful filtering and sorting options
- ✓ Mark tasks as complete
- 🗑️ Delete tasks
- 💾 Persistent storage using JSON
- 🔒 Thread-safe operations
- Go 1.21 or higher
-
Clone the repository:
git clone https://github.com/rahmanaulia/go-cli-task-manager.git cd go-cli-task-manager
-
Install dependencies:
go mod tidy
-
Build the project:
go build
.
├── cmd_test.go # Command tests with examples of testing CLI applications
├── go.mod # Go module file
├── go.sum # Go module checksums
├── main.go # Entry point with cobra CLI setup
├── storage/ # Storage package demonstrating data persistence
│ ├── storage.go # Task storage with mutex for thread safety
│ └── storage_test.go # Storage tests showing Go testing patterns
├── task.go # Task commands showing cobra CLI patterns
└── types/ # Type definitions showing Go type system
└── task.go # Task struct with JSON tags and validation
Each file contains detailed comments explaining:
- The purpose of each package and file
- Implementation details and design decisions
- Go patterns and best practices used
- Error handling strategies
- Concurrency considerations
Basic task:
./go-cli-task-manager add "Buy groceries" "Get milk and eggs"
Task with due date, priority, and tags:
./go-cli-task-manager add "Important meeting" "Team sync" -d 2024-03-30 -p high -t work,urgent
List all tasks:
./go-cli-task-manager list
Filter by tag:
./go-cli-task-manager list -t work
Filter by state:
./go-cli-task-manager list -s pending
Sort tasks:
./go-cli-task-manager list -o priority # Sort by priority
./go-cli-task-manager list -o due # Sort by due date
Mark task as complete:
./go-cli-task-manager complete 1
Delete a task:
./go-cli-task-manager delete 1
Tasks are stored in a JSON file located at ~/.taskmanager/tasks.json
. The storage implementation demonstrates:
- File I/O operations in Go
- JSON marshaling/unmarshaling
- Error handling for file operations
- Thread-safe access using mutexes
The test suite demonstrates various testing patterns in Go:
Run all tests:
go test -v ./...
Run tests with coverage:
go test -v -cover ./...
-
Package Organization
- Separation of concerns
- Interface design
- Package visibility rules
-
Concurrency
- Mutex usage
- Thread-safe operations
- Race condition prevention
-
Error Handling
- Error wrapping
- Custom error types
- Graceful error recovery
-
Testing
- Table-driven tests
- Test fixtures
- Mock interfaces
This project is primarily for learning purposes, but contributions that help demonstrate additional Go concepts are welcome:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Add detailed comments explaining the Go concepts used
- Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.