I am learning go and was looking at a simple go example web app: https://github.com/campoy/todo/blob/master/task/task.go
Having struct:
type Task struct {
ID int64 // Unique identifier
Title string // Description
Done bool // Is this task done?
}
and
// TaskManager manages a list of tasks in memory.
type TaskManager struct {
tasks []*Task
lastID int64
}
There are methods on the TaskManager func (m *TaskManager) Save(task *Task) error ... func (m *TaskManager) All() []*Task...
I am wondering how to generalize TaskManager into Manager, so it would have these same methods (namely: save, all, find) so it can be used on different structs, for example Users, which would all have ID field.
I assume constructing an array of general type doesn't fit because there is an ID in 'save' and 'find' methods