Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit be17003

Browse files
committed
added cache set and get
1 parent 3e0d351 commit be17003

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cache.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package backend
2+
3+
import "encoding/json"
4+
5+
func CacheGet(token, key string, v interface{}) error {
6+
var s string
7+
if err := Get(token, "/sudo/cache?key="+key, &s); err != nil {
8+
return err
9+
}
10+
return json.Unmarshal([]byte(s), v)
11+
}
12+
13+
func CacheSet(token, key string, v interface{}) error {
14+
b, err := json.Marshal(v)
15+
if err != nil {
16+
return err
17+
}
18+
data := new(struct {
19+
Key string `json:"key"`
20+
Value string `json:"value"`
21+
})
22+
data.Key = key
23+
data.Value = string(b)
24+
var ok bool
25+
return Post(token, "/sudo/cache", data, &ok)
26+
}

0 commit comments

Comments
 (0)