-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer.go
112 lines (93 loc) · 2.16 KB
/
pointer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package minipointer
import (
"time"
"golang.org/x/net/context"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine/memcache"
)
const (
PropNameRootGroup = "RootGroup"
PropNamePointerId = "IdentifyId"
PropNamePointerType = "PointerType"
PropNameValue = "UserName"
PropNameInfo = "Info"
PropNameUpdate = "Update"
PropNameSign = "Sign"
PropNameOwner = "Owner"
PropNamePoint = "Point"
)
type GaePointerItem struct {
RootGroup string
PointerId string
PointerType string
Value string
Info string
Update time.Time
Owner string
Sign string
Point int
}
type Pointer struct {
gaeObj *GaePointerItem
gaeKey *datastore.Key
kind string
}
func (obj *Pointer) UpdateMemcache(ctx context.Context) {
userObjMemSource := obj.ToJson()
userObjMem := &memcache.Item{
Key: obj.gaeKey.StringID(),
Value: []byte(userObjMemSource), //
}
memcache.Set(ctx, userObjMem)
}
func (obj *PointerManager) DeleteMemcache(ctx context.Context, stringId string) {
memcache.Delete(ctx, stringId)
}
func (obj *Pointer) GetId() string {
return obj.gaeObj.PointerId
}
func (obj *Pointer) GetType() string {
return obj.gaeObj.PointerType
}
func (obj *Pointer) GetValue() string {
return obj.gaeObj.Value
}
func (obj *Pointer) SetValue(v string) {
obj.gaeObj.Value = v
}
func (obj *Pointer) GetSign() string {
return obj.gaeObj.Sign
}
func (obj *Pointer) SetSign(v string) {
obj.gaeObj.Sign = v
}
func (obj *Pointer) GetOwner() string {
return obj.gaeObj.Owner
}
func (obj *Pointer) SetOwner(v string) {
obj.gaeObj.Owner = v
}
func (obj *Pointer) GetPoint() int {
return obj.gaeObj.Point
}
func (obj *Pointer) SetPoint(v int) {
obj.gaeObj.Point = v
}
func (obj *Pointer) GetInfo() string {
return obj.gaeObj.Info
}
func (obj *Pointer) GetUpdate() time.Time {
return obj.gaeObj.Update
}
func (obj *PointerManager) Save(ctx context.Context, pointer *Pointer) error {
if obj.memcachedOnly == true {
pointer.UpdateMemcache(ctx)
return nil
} else {
_, err := datastore.Put(ctx, pointer.gaeKey, pointer.gaeObj)
if err == nil {
pointer.UpdateMemcache(ctx)
}
return err
}
}