-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
31 lines (27 loc) · 963 Bytes
/
models.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
package main
type Post struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func All() []Post {
return getPosts()
}
func findByID(postID int) Post {
for _, post := range getPosts() {
if post.ID == postID {
return post
}
}
return Post{}
}
func getPosts() []Post {
return []Post{
{ID: 1, Title: "post1", Content: "this is the content of post one", CreatedAt: currentTimestamp(), UpdatedAt: currentTimestamp()},
{ID: 2, Title: "post2", Content: "this is the content of post one", CreatedAt: currentTimestamp(), UpdatedAt: currentTimestamp()},
{ID: 3, Title: "post3", Content: "this is the content of post one", CreatedAt: currentTimestamp(), UpdatedAt: currentTimestamp()},
{ID: 4, Title: "post4", Content: "this is the content of post one", CreatedAt: currentTimestamp(), UpdatedAt: currentTimestamp()},
}
}