-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtasks.go
47 lines (38 loc) · 904 Bytes
/
tasks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
// Tasks Struct with tasks items
type Tasks struct {
Items []Task
}
// Task define the data structure for
type Task struct {
Identifier string
Action string
At string
}
// AddItem add a new task to Tasks items field
func (tasks *Tasks) addItem(item Task) []Task {
tasks.Items = append(tasks.Items, item)
return tasks.Items
}
func (tasks Tasks) getByIdentifier(identifier string) Tasks {
tasksWithIdentifier := Tasks{}
for _, task := range tasks.Items {
if task.getIdentifier() != identifier {
continue
}
tasksWithIdentifier.addItem(task)
}
return tasksWithIdentifier
}
func (task Task) getIdentifier() string {
return task.Identifier
}
func (task Task) getAction() string {
return task.Action
}
func (task Task) getAt() string {
return task.At
}
func (task Task) toArrayString() []string {
return []string{task.Identifier, task.Action, task.At}
}