Level 1: CLI Task Tracker (Core Go & Testing)¶
Welcome to your first Go hands-on challenge! Your goal is to build a Command Line Interface (CLI) application to track tasks, persisted as JSON.
Features to Implement¶
Your application must support the following CLI commands:
- Add a task:
- List all tasks:
- Complete a task:
- Delete a task:
Storage & Persistence¶
- All tasks must be stored in a file named
tasks.jsonin the current working directory. - If
tasks.jsondoes not exist, the app should initialize an empty database. - The tasks must be saved dynamically after every add, complete, or delete action.
Python vs Go Cheatsheet for this Project¶
Here is how you would map typical Python patterns to Go for this project:
1. JSON Serialization¶
- Python:
- Go:
import "encoding/json" import "os" // Write data, err := json.MarshalIndent(tasks, "", " ") if err != nil { return err } err = os.WriteFile("tasks.json", data, 0644) // Read data, err := os.ReadFile("tasks.json") if err != nil { if os.IsNotExist(err) { // Handle file not existing (first run) } return err } err = json.Unmarshal(data, &tasks)
2. Classes vs Structs¶
- Python:
- Go:
3. Error Handling¶
- Python:
- Go:
Getting Started¶
- Check out task.go. We have defined the skeleton structure and function signatures.
- Check out task_test.go, which has standard tests.
- Run the tests (they will fail initially because the methods are not implemented):
- Implement the methods in task.go.
- Once your tests pass, write
main.goto handle the command-line CLI interface.