-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhot.go
52 lines (44 loc) · 889 Bytes
/
hot.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
package hot
import (
"fmt"
"time"
)
type Hot struct {
Title string
Summary string
URL string
Catalog string
Extra string
Date time.Time
PublishDate time.Time
}
func (hot *Hot) String() string {
return fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s", hot.Title, hot.Summary, hot.URL, hot.Catalog, hot.Extra, hot.Date.Format(time.RFC3339), hot.PublishDate.Format(time.RFC3339))
}
type Board struct {
Name string
Hots []*Hot
}
func NewBoard(name string) *Board {
return &Board{
Name: name,
}
}
func (b *Board) Append(hot *Hot) *Hot {
if hot.Date.IsZero() {
hot.Date = time.Now()
}
if hot.PublishDate.IsZero() {
hot.PublishDate = time.Now()
}
b.Hots = append(b.Hots, hot)
return hot
}
type Crawler interface {
Name() string
Crawl() (*Board, error)
}
type Archiver interface {
Name() string
Archive(*Board) (int, error)
}