Documentation ¶
Index ¶
- Constants
- Variables
- func CheckMessage(req PushNotification) error
- func CheckPushConf() error
- func GetAndroidNotification(req PushNotification) gcm.HttpMessage
- func GetIOSNotification(req PushNotification) *apns.Notification
- func GetVersion() string
- func InitAPNSClient() error
- func InitAppStatus() error
- func InitLog() error
- func InitWorkers(workerNum int64, queueNum int64)
- func LogMiddleware() gin.HandlerFunc
- func LogPush(status, token string, req PushNotification, errPush error)
- func LogRequest(uri string, method string, ip string, contentType string, agent string)
- func PrintGoRushVersion()
- func PushToAndroid(req PushNotification) bool
- func PushToIOS(req PushNotification) bool
- func RunHTTPServer() error
- func SetLogLevel(log *logrus.Logger, levelString string) error
- func SetLogOut(log *logrus.Logger, outString string) error
- func SetProxy(proxy string) error
- func SetVersion(ver string)
- func StatMiddleware() gin.HandlerFunc
- func VersionMiddleware() gin.HandlerFunc
- type Alert
- type AndroidStatus
- type D
- type IosStatus
- type LogPushEntry
- type LogReq
- type PushNotification
- type RequestPush
- type StatusApp
- type Storage
Constants ¶
const ( // PlatFormIos constant is 1 for iOS PlatFormIos = iota + 1 // PlatFormAndroid constant is 2 for Android PlatFormAndroid )
const ( // SucceededPush is log block SucceededPush = "succeeded-push" // FailedPush is log block FailedPush = "failed-push" )
const ( TotalCountKey = "gorush-total-count" IosSuccessKey = "gorush-ios-success-count" IosErrorKey = "gorush-ios-error-count" AndroidSuccessKey = "gorush-android-success-count" AndroidErrorKey = "gorush-android-error-count" )
Stat variable for redis
const ( // ApnsPriorityLow will tell APNs to send the push message at a time that takes // into account power considerations for the device. Notifications with this // priority might be grouped and delivered in bursts. They are throttled, and // in some cases are not delivered. ApnsPriorityLow = 5 // ApnsPriorityHigh will tell APNs to send the push message immediately. // Notifications with this priority must trigger an alert, sound, or badge on // the target device. It is an error to use this priority for a push // notification that contains only the content-available key. ApnsPriorityHigh = 10 )
Variables ¶
var ( // PushConf is gorush config PushConf config.ConfYaml // QueueNotification is chan type QueueNotification chan PushNotification // CertificatePemIos is ios certificate file CertificatePemIos tls.Certificate // ApnsClient is apns client ApnsClient *apns.Client // LogAccess is log server request log LogAccess *logrus.Logger // LogError is log server error log LogError *logrus.Logger // StatStorage implements the storage interface StatStorage Storage )
var Stats = stats.New()
Stats provide response time, status code count, etc.
Functions ¶
func CheckMessage ¶
func CheckMessage(req PushNotification) error
CheckMessage for check request message
func GetAndroidNotification ¶
func GetAndroidNotification(req PushNotification) gcm.HttpMessage
GetAndroidNotification use for define Android notificaiton. HTTP Connection Server Reference for Android https://developers.google.com/cloud-messaging/http-server-ref
func GetIOSNotification ¶
func GetIOSNotification(req PushNotification) *apns.Notification
GetIOSNotification use for define iOS notificaiton. The iOS Notification Payload ref: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
func InitWorkers ¶
InitWorkers for initialize all workers.
func LogPush ¶
func LogPush(status, token string, req PushNotification, errPush error)
LogPush record user push request and server response.
func LogRequest ¶
LogRequest record http request
func PushToAndroid ¶
func PushToAndroid(req PushNotification) bool
PushToAndroid provide send notification to Android server.
func PushToIOS ¶
func PushToIOS(req PushNotification) bool
PushToIOS provide send notification to APNs server.
func SetLogLevel ¶
SetLogLevel is define log level what you want log level: panic, fatal, error, warn, info and debug
func StatMiddleware ¶
func StatMiddleware() gin.HandlerFunc
StatMiddleware response time, status code count, etc.
func VersionMiddleware ¶
func VersionMiddleware() gin.HandlerFunc
VersionMiddleware : add version on header.
Types ¶
type Alert ¶
type Alert struct { Action string `json:"action,omitempty"` ActionLocKey string `json:"action-loc-key,omitempty"` Body string `json:"body,omitempty"` LaunchImage string `json:"launch-image,omitempty"` LocArgs []string `json:"loc-args,omitempty"` LocKey string `json:"loc-key,omitempty"` Title string `json:"title,omitempty"` Subtitle string `json:"subtitle,omitempty"` TitleLocArgs []string `json:"title-loc-args,omitempty"` TitleLocKey string `json:"title-loc-key,omitempty"` }
Alert is APNs payload
type AndroidStatus ¶
type AndroidStatus struct { PushSuccess int64 `json:"push_success"` PushError int64 `json:"push_error"` }
AndroidStatus is android structure
type IosStatus ¶
type IosStatus struct { PushSuccess int64 `json:"push_success"` PushError int64 `json:"push_error"` }
IosStatus is iOS structure
type LogPushEntry ¶
type LogPushEntry struct { Type string `json:"type"` Platform string `json:"platform"` Token string `json:"token"` Message string `json:"message"` Error string `json:"error"` // Android To string `json:"to,omitempty"` CollapseKey string `json:"collapse_key,omitempty"` DelayWhileIdle bool `json:"delay_while_idle,omitempty"` TimeToLive uint `json:"time_to_live,omitempty"` RestrictedPackageName string `json:"restricted_package_name,omitempty"` DryRun bool `json:"dry_run,omitempty"` // iOS ApnsID string `json:"apns_id,omitempty"` Topic string `json:"topic,omitempty"` Badge int `json:"badge,omitempty"` Sound string `json:"sound,omitempty"` Category string `json:"category,omitempty"` }
LogPushEntry is push response log
type LogReq ¶
type LogReq struct { URI string `json:"uri"` Method string `json:"method"` IP string `json:"ip"` ContentType string `json:"content_type"` Agent string `json:"agent"` }
LogReq is http request log
type PushNotification ¶
type PushNotification struct { // Common Tokens []string `json:"tokens" binding:"required"` Platform int `json:"platform" binding:"required"` Message string `json:"message,omitempty"` Title string `json:"title,omitempty"` Priority string `json:"priority,omitempty"` ContentAvailable bool `json:"content_available,omitempty"` Sound string `json:"sound,omitempty"` Data D `json:"data,omitempty"` Retry int `json:"retry,omitempty"` // Android APIKey string `json:"api_key,omitempty"` To string `json:"to,omitempty"` CollapseKey string `json:"collapse_key,omitempty"` DelayWhileIdle bool `json:"delay_while_idle,omitempty"` TimeToLive *uint `json:"time_to_live,omitempty"` RestrictedPackageName string `json:"restricted_package_name,omitempty"` DryRun bool `json:"dry_run,omitempty"` Notification gcm.Notification `json:"notification,omitempty"` // iOS Expiration int64 `json:"expiration,omitempty"` ApnsID string `json:"apns_id,omitempty"` Topic string `json:"topic,omitempty"` Badge *int `json:"badge,omitempty"` Category string `json:"category,omitempty"` URLArgs []string `json:"url-args,omitempty"` Alert Alert `json:"alert,omitempty"` }
PushNotification is single notification request
type RequestPush ¶
type RequestPush struct {
Notifications []PushNotification `json:"notifications" binding:"required"`
}
RequestPush support multiple notification request.
type StatusApp ¶
type StatusApp struct { Version string `json:"version"` QueueMax int `json:"queue_max"` QueueUsage int `json:"queue_usage"` TotalCount int64 `json:"total_count"` Ios IosStatus `json:"ios"` Android AndroidStatus `json:"android"` }
StatusApp is app status structure
type Storage ¶
type Storage interface { Init() error Reset() AddTotalCount(int64) AddIosSuccess(int64) AddIosError(int64) AddAndroidSuccess(int64) AddAndroidError(int64) GetTotalCount() int64 GetIosSuccess() int64 GetIosError() int64 GetAndroidSuccess() int64 GetAndroidError() int64 }
Storage interface