-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathutils.go
60 lines (53 loc) · 1020 Bytes
/
utils.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
package pdd
import (
"github.com/bitly/go-simplejson"
"fmt"
)
// the basic call method
func Call(context *Context, params Params) (r []byte, err error) {
params.Sign(context)
r, err = Post(context, params.GetQuery())
return
}
// 兼容多层 Key 读取
func GetResponseBytes(data []byte, keys ...string) (b []byte, err error) {
js, err := simplejson.NewJson(data)
if err != nil {
return
}
for _, key := range keys {
js = js.Get(key)
}
b, err = js.Encode()
return
}
func GetResponseArrayIndexBytes(data []byte, index int, keys ...string) (b []byte, err error) {
js, err := simplejson.NewJson(data)
if err != nil {
return
}
for _, key := range keys {
js = js.Get(key)
}
js = js.GetIndex(index)
b, err = js.Encode()
return
}
func TransformPids(pids []string) (r string) {
if len(pids) == 0 {
return ""
}
if len(pids) == 1 {
return fmt.Sprintf(`["%s"]`, pids[0])
}
r += `["`
for k, v := range pids {
if k == 0 {
r += v
} else {
r += "," + v
}
}
r += `"]`
return
}