-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
61 lines (51 loc) · 1.23 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"time"
)
type source struct {
ID interface{} `json:"id"`
Name string `json:"name"`
}
type article struct {
Source source `json:"source"`
Author string `json:"author"`
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
URLToImage string `json:"urlToImage"`
PublishedAt time.Time `json:"publishedAt"`
Content string `json:"content"`
}
func (a *article) FormatPublishedDate() string {
year, month, day := a.PublishedAt.Date()
return fmt.Sprintf("%v %d, %d", month, day, year)
}
type results struct {
Status string `json:"status"`
TotalResults int `json:"totalResults"`
Articles []article `json:"articles"`
}
type newsAPIError struct {
Status string `json:"status"`
Code string `json:"code"`
Message string `json:"message"`
}
type searchNews struct {
SearchKey string
NextPage int
TotalPages int
Results results
}
func (s *searchNews) IsLastPage() bool {
return s.NextPage >= s.TotalPages
}
func (s *searchNews) CurrentPage() int {
if s.NextPage == 1 {
return s.NextPage
}
return s.NextPage - 1
}
func (s *searchNews) PreviousPage() int {
return s.CurrentPage() - 1
}