-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon.go
More file actions
61 lines (52 loc) · 1.58 KB
/
common.go
File metadata and controls
61 lines (52 loc) · 1.58 KB
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
package jpush
import "fmt"
// VERSION api client version
const (
VERSION = "1.0"
)
// ZONES define api url
var ZONES = make(map[string]map[string]string)
func init() {
ZONES["default"] = map[string]string{
"push": "https://api.jpush.cn/v3/",
"report": "https://report.jpush.cn/v3/",
"device": "https://device.jpush.cn/v3/devices/",
"alias": "https://device.jpush.cn/v3/aliases/",
"tag": "https://device.jpush.cn/v3/tags/",
"schedule": "https://api.jpush.cn/v3/schedules/",
"admin": "https://admin.jpush.cn/v1/",
}
ZONES["bj"] = map[string]string{
"push": "https://bjapi.push.jiguang.cn/v3/",
"report": "https://bjapi.push.jiguang.cn/v3/report/",
"device": "https://bjapi.push.jiguang.cn/v3/device/",
"alias": "https://bjapi.push.jiguang.cn/v3/device/aliases/",
"tag": "https://bjapi.push.jiguang.cn/v3/device/tags/",
"schedule": "https://bjapi.push.jiguang.cn/v3/push/schedules/",
"admin": "https://admin.jpush.cn/v1/",
}
}
// GetURL get the api url address
func (j *JPush) GetURL(key string) string {
if urls, ok := ZONES[j.Zone]; ok {
if url, ok := urls[key]; ok {
return url
}
}
return ZONES["default"]["push"]
}
// ErrorMessage error message response
type ErrorMessage struct {
Code int `json:"code"`
Message string `json:"message"`
}
// ErrorResponse error response from api
type ErrorResponse struct {
Error ErrorMessage `json:"error"`
}
func (e ErrorMessage) Error() string {
return fmt.Sprintf("JPush Error %d: %s", e.Code, e.Message)
}
// DefaultResponse default null response
type DefaultResponse struct {
}