-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.go
executable file
·45 lines (38 loc) · 989 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
package main
import "fmt"
var currentId int
var todos Todos // Todo
var paths Path // Path
func init() {
RepoCreateTodo(Todo{Name: "Write presentation"})
RepoCreateTodo(Todo{Name: "Host meetup"})
RepoCreatePath(Location{Latitude: "0.53", Longitude: "43.54", Timestamp: "dsfdf"})
RepoCreatePath(Location{Latitude: "0.653", Longitude: "44.54", Timestamp: "dwedwed"})
}
func RepoFindTodo(id int) Todo {
for _, t := range todos {
if t.Id == id {
return t
}
}
return Todo{} // return empty Todo if not found
}
func RepoCreateTodo(t Todo) Todo {
currentId += 1
t.Id = currentId
todos = append(todos, t)
return t //this is bad, I don't think it passes race condtions
}
func RepoDestroyTodo(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)
}
func RepoCreatePath(l Location) Location {
paths = append(paths, l)
return l
}