-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
45 lines (37 loc) · 969 Bytes
/
model.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
package main
import "reflect"
// Task holds all the info about task :(.
type Task struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"desc"`
}
// Tasks holds all tasks.
var Tasks = []Task{}
// NewTask is constructor for creating new task.
func NewTask(id, name, desc string) Task { return Task{ID: id, Name: name, Description: desc} }
// TaskbyID fetches the task by ID.
func TaskbyID(id string) Task {
for _, task := range Tasks {
if task.ID == id {
return task
}
}
// could not find anything , so returning empty task
return Task{}
}
// Equals compares 2 IDs.
func Equals(t, t2 Task) bool {
return reflect.DeepEqual(t, t2)
}
// ModelUpdateTask updates the task.
func ModelUpdateTask(id, name, desc string) Task {
for _, task := range Tasks {
if task.ID == id {
task.Name = name
task.Description = desc
return task
}
}
return NewTask("1", "name", "desc, this is error")
}