-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.go
81 lines (64 loc) · 1.39 KB
/
entry.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package model
import (
"github.com/vinicius73/gamer-feed/pkg/support"
)
var _ IEntry = (*Entry)(nil) // Ensure that Entry implements IEntry.
type IEntry interface {
Text() string
Link() string
Tags() []string
Source() string
ImageURL() string
Hash() (string, error)
HasStory() bool
SetHasStory(bool) IEntry
FillFrom(IEntry) IEntry
}
type Entry struct {
Title string `json:"title"`
URL string `json:"url"`
Image string `json:"image_url"`
Categories []string `json:"categories"`
SourceName string `json:"source"`
HaveStory bool `json:"has_story"`
}
// Hash of entry.
func (e Entry) Hash() (string, error) {
return support.HashSHA256(e.URL)
}
func (e Entry) Text() string {
return e.Title
}
func (e Entry) ImageURL() string {
return e.Image
}
func (e Entry) Link() string {
return e.URL
}
func (e Entry) Tags() []string {
return []string{e.SourceName}
}
func (e Entry) Source() string {
return e.SourceName
}
func (e Entry) HasStory() bool {
return e.HaveStory
}
func (e Entry) SetHasStory(hasStory bool) IEntry {
e.HaveStory = hasStory
return e
}
func (e Entry) FillFrom(input IEntry) IEntry {
if actual, ok := input.(Entry); ok {
return actual
}
e = Entry{
Title: input.Text(),
URL: input.Link(),
Image: input.ImageURL(),
Categories: input.Tags(),
SourceName: input.Source(),
HaveStory: input.HasStory(),
}
return e
}