This repository has been archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
70 lines (56 loc) · 1.54 KB
/
types.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
package hydrocarbon
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"time"
)
// A Folder holds a collection of feeds
type Folder struct {
ID string `json:"id"`
Title string `json:"title"`
Feeds []*Feed `json:"feeds"`
}
// A Feed is a collection of posts
type Feed struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title"`
Plugin string `json:"plugin"`
BaseURL string `json:"base_url"`
Unread int `json:"unread"`
Posts []*Post `json:"posts"`
}
// A Post is a single post on a feed
type Post struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
PostedAt time.Time `json:"posted_at"`
UpdatedAt time.Time `json:"updated_at"`
// TODO(fortytw2): normalize this
OriginalURL string `json:"original_url"`
URL string `json:"url"`
Title string `json:"title"`
Author string `json:"author"`
Body string `json:"body"`
Read bool `json:"read"`
Extra map[string]interface{} `json:"extra"`
}
// ContentHash returns the stable hex encoded SHA256 of a post
func (p *Post) ContentHash() string {
h := sha256.New()
_, err := h.Write([]byte(fmt.Sprintf("%s:%s:%s", p.Title, p.Author, p.Body)))
if err != nil {
// pretty certain this cannot error
panic(err)
}
return hex.EncodeToString(h.Sum(nil))
}
// A Session is a session
type Session struct {
CreatedAt time.Time `json:"created_at"`
UserAgent string `json:"user_agent"`
IP string `json:"ip"`
Active bool `json:"active"`
}