common

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUSH_URL          = push_host + "/v3/push"
	PUSH_VALIDATE_URL = push_host + "/v3/push/validate"

	// GET /v3/devices/{registration_id}
	DEVICE_URL = device_host + "/v3/devices/%s"

	QUERY_TAGS_URL = device_host + "/v3/tags/"
	// GET /v3/tags/{tag_value}/registration_ids/{registration_id}
	CHECK_TAG_USER_EXISTS_URL = device_host + "/v3/tags/%s/registration_ids/%s"
	// POST /v3/tags/{tag_value}
	UPDATE_TAG_USERS_URL = device_host + "/v3/tags/%s"
	// DELETE /v3/tags/{tag_value}
	DELETE_TAG_URL = device_host + "/v3/tags/%s"

	// GET /v3/aliases/{alias_value}
	QUERY_ALIAS_URL = device_host + "/v3/aliases/%s"
	// DELETE /v3/aliases/{alias_value}
	DELETE_ALIAS_URL = device_host + "/v3/aliases/%s"

	// GET /v3/received
	RECEIVED_REPORT_URL = report_host + "/v3/received"
)

Variables

View Source
var (
	ErrInvalidPlatform         = errors.New("<Platform>: invalid platform")
	ErrMessageContentMissing   = errors.New("<Message>: msg_content is required.")
	ErrContentMissing          = errors.New("<PushObject>: notification or message is required")
	ErrIosNotificationTooLarge = errors.New("<IosNotification>: iOS notification too large")
)

Functions

func BasicAuth

func BasicAuth(username, password string) string

func EqualStringSlice

func EqualStringSlice(a []string, b []string) bool

func GetIntHeader

func GetIntHeader(resp *http.Response, key string) (int, error)

func MinInt

func MinInt(a, b int) int

func RespToJson

func RespToJson(resp *http.Response, dest interface{}) error

func UniqString

func UniqString(a []string) []string

Types

type ErrorResult

type ErrorResult struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*ErrorResult) String

func (pe *ErrorResult) String() string

type RateLimitInfo

type RateLimitInfo struct {
	RateLimitQuota     int
	RateLimitRemaining int
	RateLimitReset     int
}

func NewRateLimitInfo

func NewRateLimitInfo(resp *http.Response) *RateLimitInfo

所有的 HTTP API Response Header 里都加了三项频率控制信息:

X-Rate-Limit-Limit: 当前 AppKey 一个时间窗口内可调用次数 X-Rate-Limit-Remaining:当前时间窗口剩余的可用次数 X-Rate-Limit-Reset: 距离时间窗口重置剩余的秒数

func (*RateLimitInfo) String

func (info *RateLimitInfo) String() string

type ResponseBase

type ResponseBase struct {
	// HTTP 状态码
	StatusCode int

	// 频率限制相关
	RateLimitInfo *RateLimitInfo

	// 错误相关
	Error *ErrorResult `json:"error"`
}

func NewResponseBase

func NewResponseBase(resp *http.Response) ResponseBase

func ResponseOrError

func ResponseOrError(resp *http.Response, err error) (*ResponseBase, error)

func (*ResponseBase) Ok

func (rb *ResponseBase) Ok() bool

根据请求返回的 HTTP 状态码判断推送是否成功 规范: - 200 一定是正确。所有异常都不使用 200 返回码 - 业务逻辑上的错误,有特别的错误码尽量使用 4xx,否则使用 400。 - 服务器端内部错误,无特别错误码使用 500。 - 业务异常时,返回内容使用 JSON 格式定义 error 信息。

更多细节: http://docs.jpush.io/server/http_status_code/

func (*ResponseBase) String

func (rb *ResponseBase) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL