/
metadata.go
50 lines (43 loc) · 1.27 KB
/
metadata.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
package favdb
import (
"encoding/json"
"log"
)
type Model struct {
Db UserFavData
Log *log.Logger
}
type MessageCount struct {
All int `json:"all"`
Boo int `json:"boo"`
Count int `json:"count"`
Neutral int `json:"neutral"`
Push int `json:"push"`
}
type ArticleDocument struct {
ArticleID string `json:"article_id"`
ArticleTitle string `json:"article_title"`
Author string `json:"author"`
Board string `json:"board"`
Content string `json:"content"`
Date string `json:"date"`
IP string `json:"ip"`
MessageCount MessageCount `bson:"message_count"`
Messages []interface{} `json:"messages"`
Timestamp int `json:"timestamp"`
URL string `json:"url"`
ImageLinks []string `json:"image_links"`
}
func (d *ArticleDocument) ToString() (info string) {
b, err := json.Marshal(d)
if err != nil {
//fmt.Println(err)
return
}
return string(b)
}
// ArticleDocument for sorting.
type AllArticles []ArticleDocument
func (a AllArticles) Len() int { return len(a) }
func (a AllArticles) Less(i, j int) bool { return a[i].MessageCount.Count > a[j].MessageCount.Count }
func (a AllArticles) Swap(i, j int) { a[i], a[j] = a[j], a[i] }