gorush

package
v1.10.35 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PlatformIos constant is 1 for iOS
	PlatformIos = iota + 1
	// PlatformAndroid constant is 2 for Android
	PlatformAndroid
	// PlatformWeb constant is 3 for Web
	PlatformWeb
)
View Source
const (
	// SucceededPush is log block
	SucceededPush = "succeeded-push"
	// FailedPush is log block
	FailedPush = "failed-push"
)
View Source
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

View Source
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

View Source
var (
	// PushConf is gorush config
	PushConf config.ConfYaml
	// QueueNotification is chan type
	QueueNotification chan PushNotification
	// ApnsClient is apns client
	ApnsClient *apns2.Client
	// VoipApnsClient is apns client
	VoipApnsClient *apns2.Client
	// FCMClient is apns client
	FCMClient *fcm.Client
	// WebClient is web client
	WebClient *web.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.Storage
	// MaxConcurrentIOSPushes pool to limit the number of concurrent iOS pushes
	MaxConcurrentIOSPushes chan struct{}
)
View Source
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 CheckPushConf

func CheckPushConf() error

CheckPushConf provide check your yml config.

func DispatchFeedback added in v1.10.24

func DispatchFeedback(log LogPushEntry, url string, timeout int64) error

DispatchFeedback sends a feedback to the configured gateway.

func GetAndroidNotification

func GetAndroidNotification(req PushNotification) *fcm.Message

GetAndroidNotification use for define Android notification. HTTP Connection Server Reference for Android https://firebase.google.com/docs/cloud-messaging/http-server-ref

func GetVersion

func GetVersion() string

GetVersion for get current version.

func InitAPNSClient

func InitAPNSClient() error

InitAPNSClient use for initialize APNs Client.

func InitAppStatus

func InitAppStatus() error

InitAppStatus for initialize app status

func InitFCMClient added in v1.10.1

func InitFCMClient(key string) (*fcm.Client, error)

InitFCMClient use for initialize FCM Client.

func InitLog

func InitLog() error

InitLog use for initial log module

func InitWebClient added in v1.10.1

func InitWebClient() error

InitWebClient use for initialize APNs Client.

func InitWorkers

func InitWorkers(ctx context.Context, wg *sync.WaitGroup, workerNum int64, queueNum int64)

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 PrintGoRushVersion

func PrintGoRushVersion()

PrintGoRushVersion provide print server engine

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 PushToWeb added in v1.10.1

func PushToWeb(req PushNotification) bool

PushToWeb provide send notification to Web server.

func RunHTTPServer

func RunHTTPServer(ctx context.Context) (err error)

RunHTTPServer provide run http or https protocol.

func SendNotification added in v1.10.1

func SendNotification(ctx context.Context, req PushNotification)

SendNotification is send message to iOS or Android

func SetLogLevel

func SetLogLevel(log *logrus.Logger, levelString string) error

SetLogLevel is define log level what you want log level: panic, fatal, error, warn, info and debug

func SetLogOut

func SetLogOut(log *logrus.Logger, outString string) error

SetLogOut provide log stdout and stderr output

func SetProxy added in v1.6.0

func SetProxy(proxy string) error

SetProxy only working for FCM server.

func SetVersion

func SetVersion(ver string)

SetVersion for setup version string.

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"`
	SummaryArg      string   `json:"summary-arg,omitempty"`
	SummaryArgCount int      `json:"summary-arg-count,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 D

type D map[string]interface{}

D provide string array

type IosStatus

type IosStatus struct {
	PushSuccess int64 `json:"push_success"`
	PushError   int64 `json:"push_error"`
}

IosStatus is iOS structure

type LogPushEntry

type LogPushEntry struct {
	ID       string `json:"notif_id,omitempty"`
	Type     string `json:"type"`
	Platform string `json:"platform"`
	Token    string `json:"token"`
	Message  string `json:"message"`
	Error    string `json:"error"`
}

LogPushEntry is push response log

type Metrics added in v1.7.4

type Metrics struct {
	TotalIosSuccess     *prometheus.Desc
	TotalIosError       *prometheus.Desc
	TotalAndroidSuccess *prometheus.Desc
	TotalAndroidError   *prometheus.Desc
	TotalWebSuccess     *prometheus.Desc
	TotalWebError       *prometheus.Desc
	PushCount           *prometheus.Desc
	WebSuccess          *prometheus.Desc
	WebError            *prometheus.Desc
	TotalPushCount      *prometheus.Desc
	IosSuccess          *prometheus.Desc
	IosError            *prometheus.Desc
	AndroidSuccess      *prometheus.Desc
	AndroidError        *prometheus.Desc
	QueueUsage          *prometheus.Desc
}

Metrics implements the prometheus.Metrics interface and exposes gorush metrics for prometheus

func NewMetrics added in v1.7.4

func NewMetrics() Metrics

NewMetrics returns a new Metrics with all prometheus.Desc initialized

func (Metrics) Collect added in v1.7.4

func (c Metrics) Collect(ch chan<- prometheus.Metric)

Collect returns the metrics with values

func (Metrics) Describe added in v1.7.4

func (c Metrics) Describe(ch chan<- *prometheus.Desc)

Describe returns all possible prometheus.Desc

type PushNotification

type PushNotification struct {

	// Common
	ID               string      `json:"notif_id,omitempty"`
	Tokens           []string    `json:"tokens" binding:"required"`
	Platform         int         `json:"platform" binding:"required"`
	Message          string      `json:"message,omitempty"`
	Title            string      `json:"title,omitempty"`
	Image            string      `json:"image,omitempty"`
	Priority         string      `json:"priority,omitempty"`
	ContentAvailable bool        `json:"content_available,omitempty"`
	MutableContent   bool        `json:"mutable_content,omitempty"`
	Sound            interface{} `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"`
	Condition             string            `json:"condition,omitempty"`
	Notification          *fcm.Notification `json:"notification,omitempty"`

	// iOS
	Voip        bool     `json:"voip,omitempty"`
	Expiration  *int64   `json:"expiration,omitempty"`
	ApnsID      string   `json:"apns_id,omitempty"`
	CollapseID  string   `json:"collapse_id,omitempty"`
	Topic       string   `json:"topic,omitempty"`
	PushType    string   `json:"push_type,omitempty"`
	Badge       *int     `json:"badge,omitempty"`
	Category    string   `json:"category,omitempty"`
	ThreadID    string   `json:"thread-id,omitempty"`
	URLArgs     []string `json:"url-args,omitempty"`
	Alert       Alert    `json:"alert,omitempty"`
	Production  bool     `json:"production,omitempty"`
	Development bool     `json:"development,omitempty"`
	SoundName   string   `json:"name,omitempty"`
	SoundVolume float32  `json:"volume,omitempty"`
	Apns        D        `json:"apns,omitempty"`

	// Web
	Subscriptions []Subscription `json:"subscriptions,omitempty"`
	// contains filtered or unexported fields
}

PushNotification is single notification request

func (*PushNotification) AddLog added in v1.8.1

func (p *PushNotification) AddLog(log LogPushEntry)

AddLog record fail log of notification

func (*PushNotification) AddWaitCount added in v1.8.1

func (p *PushNotification) AddWaitCount()

AddWaitCount increments the WaitGroup counter.

func (*PushNotification) IsTopic added in v1.10.1

func (p *PushNotification) IsTopic() bool

IsTopic check if message format is topic for FCM ref: https://firebase.google.com/docs/cloud-messaging/send-message#topic-http-post-request

func (*PushNotification) WaitDone added in v1.8.1

func (p *PushNotification) WaitDone()

WaitDone decrements the WaitGroup counter.

type RequestPush

type RequestPush struct {
	Notifications []PushNotification `json:"notifications" binding:"required"`
	Sync          *bool              `json:"sync,omitempty"`
	CallbackUrl   *string            `json:"callback_url,omitempty"`
}

RequestPush support multiple notification request.

type Sound added in v1.10.24

type Sound struct {
	Critical int     `json:"critical,omitempty"`
	Name     string  `json:"name,omitempty"`
	Volume   float32 `json:"volume,omitempty"`
}

Sound sets the aps sound on the payload.

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"`
	Web        WebStatus     `json:"web"`
}

StatusApp is app status structure

type Subscription added in v1.10.1

type Subscription struct {
	Endpoint string `json:"endpoint" binding:"required"`
	Key      string `json:"key" binding:"required"`
	Auth     string `json:"auth" binding:"required"`
}

Subscription is the Webpush subscription object.

type WebStatus added in v1.10.1

type WebStatus struct {
	PushSuccess int64 `json:"push_success"`
	PushError   int64 `json:"push_error"`
}

WebStatus is web structure

Jump to

Keyboard shortcuts

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