QTodo is a task management library written in Go that provides functionality for creating, managing, and scheduling tasks.
- Create time-scheduled tasks
- Define custom actions for each task
- Manage active and inactive tasks
- In-memory task storage
- Optional automatic task deletion after execution
To use this library, first create instances of Database
and Application
:
db := qtodo.NewDatabase()
app := qtodo.NewApp(db)
// Create a task that will execute in 5 minutes
futureTime := time.Now().Add(5 * time.Minute)
err := app.AddTask(
"my-task", // task name
"This is a test task", // description
futureTime, // execution time
func() { // action
fmt.Println("Task executed!")
},
true, // delete after execution
)
err := app.StartTask("my-task")
if err != nil {
log.Fatal(err)
}
app.StopTask("my-task")
// Get all tasks
allTasks := app.GetTaskList()
// Get active tasks
activeTasks := app.GetActiveTaskList()
app.go
: Main application implementation and task managementrepository.go
: Task storage managementtask.go
: Task structure definition and related methods
- Tasks cannot have empty names or descriptions
- Task execution time must be in the future
- Task names must be unique
- Tasks can be automatically deleted after execution
package main
import (
"fmt"
"time"
"github.com/your-username/qtodo"
)
func main() {
// Create new instances
db := qtodo.NewDatabase()
app := qtodo.NewApp(db)
// Add new task
err := app.AddTask(
"reminder",
"Meeting reminder",
time.Now().Add(1 * time.Hour),
func() {
fmt.Println("It's time for the meeting!")
},
true,
)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Start the task
err = app.StartTask("reminder")
if err != nil {
fmt.Printf("Error starting task: %v\n", err)
return
}
// Keep the program running
time.Sleep(2 * time.Hour)
}
- Go 1.11 or higher
This project is released under the MIT License.