-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.go
47 lines (40 loc) · 847 Bytes
/
repo.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
import "fmt"
import "log"
var currentId int
var todos Todos
func init() {
}
func RepoFindTodo(id int) Todo {
for _, t := range todos {
if t.Id == id {
return t
}
}
return Todo{}
}
func RepoCreateTodo(t Todo) Todo {
currentId += 1
t.Id = currentId
todos = append(todos, t)
return t
}
func RepoCompleteTodo(id int) Todo {
for i, t := range todos {
if t.Id == id {
log.Printf("todoId: %d", id)
todos[i].Completed = true
return t
}
}
return Todo{}
}
func RepoRemoveTodo(id int) error {
for i, t := range todos {
if t.Id == id {
todos = append(todos[:i], todos[i+1:]...)
return nil
}
}
return fmt.Errorf("Could not find Todo with id of %d to delete", id)
}