forked from izumin5210/ro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.go
78 lines (64 loc) · 1.72 KB
/
post.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
package rotesting
import (
"bytes"
"encoding/gob"
"fmt"
"github.com/alunir/ro"
)
// Post is a test object
type Post struct {
ID uint64 `redis:"id"`
Title string `redis:"title"`
Body string `redis:"body"`
UpdatedAt int64 `redis:"updated_at"`
}
// GetKeySuffix implements the types.Model interface
func (p *Post) GetKeySuffix() string {
return fmt.Sprint(p.ID)
}
// GetScoreMap implements the types.Model interface
func (p *Post) GetScoreMap() map[string]interface{} {
return map[string]interface{}{
"id": p.ID,
"recent": p.UpdatedAt,
}
}
// Serialized implements the types.Model interface
func (p *Post) Serialized() []byte {
return []byte{}
}
// Deserialized implements the types.Model interface
func (p *Post) Deserialized(b []byte) {}
func (p *Post) GetDatabaseNo() string { return "0" }
type Post_Serialized struct {
ro.Model
ID uint64 `redis:"id"`
UserID uint64 `redis:"user_id"`
Title string `redis:"title"`
Body string `redis:"body"`
CreatedAt int64 `redis:"created_at"`
}
func (p *Post_Serialized) GetKeySuffix() string {
return fmt.Sprint(p.ID)
}
func (p *Post_Serialized) GetScoreMap() map[string]interface{} {
return map[string]interface{}{
"recent": p.CreatedAt,
fmt.Sprintf("user:%d", p.UserID): p.CreatedAt,
}
}
func (p *Post_Serialized) Serialized() []byte {
buf := bytes.NewBuffer(nil)
err := gob.NewEncoder(buf).Encode(p)
if err != nil {
panic("Failed to Serialized")
}
return buf.Bytes()
}
func (p *Post_Serialized) Deserialized(b []byte) {
err := gob.NewDecoder(bytes.NewBuffer(b)).Decode(p)
if err != nil {
panic("Failed to Deserialized. " + err.Error())
}
}
func (p *Post_Serialized) GetDatabaseNo() string { return "0" }