gorush

package
v0.0.0-...-4d91f4f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2016 License: MIT Imports: 22 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
)
View Source
const (
	// SucceededPush is log block
	SucceededPush = "succeeded-push"
	// FailedPush is log block
	FailedPush = "failed-push"
)
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
)
View Source
const (
	// Version is gorush server version.
	Version = "1.1.0"
)

Variables

View Source
var (
	// PushConf is gorush config
	PushConf 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
	// RushStatus is notification status
	RushStatus StatusApp
	// RedisClient is global variable for redis
	RedisClient *redis.Client
)

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 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 InitAPNSClient

func InitAPNSClient() error

InitAPNSClient use for initialize APNs Client.

func InitAppStatus

func InitAppStatus()

InitAppStatus for initialize app status

func InitLog

func InitLog() error

InitLog use for initial log module

func InitWorkers

func InitWorkers(workerNum, queueNum int)

InitWorkers for initialize all workers.

func LogMiddleware

func LogMiddleware() gin.HandlerFunc

LogMiddleware provide gin router handler.

func LogPush

func LogPush(status, token string, req PushNotification, errPush error)

LogPush record user push request and server response.

func LogRequest

func LogRequest(uri string, method string, ip string, contentType string, agent string)

LogRequest record http request

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 RunHTTPServer

func RunHTTPServer() error

RunHTTPServer provide run http or https protocol.

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 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"`
	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 ConfYaml

type ConfYaml struct {
	Core    SectionCore    `yaml:"core"`
	API     SectionAPI     `yaml:"api"`
	Android SectionAndroid `yaml:"android"`
	Ios     SectionIos     `yaml:"ios"`
	Log     SectionLog     `yaml:"log"`
	Stat    SectionStat    `yaml:stat`
}

ConfYaml is config structure.

func BuildDefaultPushConf

func BuildDefaultPushConf() ConfYaml

BuildDefaultPushConf is default config setting.

func LoadConfYaml

func LoadConfYaml(confPath string) (ConfYaml, error)

LoadConfYaml provide load yml config.

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 {
	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" binding:"required"`
	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"`

	// 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 SectionAPI

type SectionAPI struct {
	PushURI    string `yaml:"push_uri"`
	StatGoURI  string `yaml:"stat_go_uri"`
	StatAppURI string `yaml:"stat_app_uri"`
	ConfigURI  string `yaml:"config_uri"`
}

SectionAPI is sub seciont of config.

type SectionAndroid

type SectionAndroid struct {
	Enabled bool   `yaml:"enabled"`
	APIKey  string `yaml:"apikey"`
}

SectionAndroid is sub seciont of config.

type SectionBoltDB

type SectionBoltDB struct {
	Path   string `yaml:"path"`
	Bucket string `yaml:"bucket"`
}

SectionBoltDB is sub seciont of config.

type SectionCore

type SectionCore struct {
	Port            string `yaml:"port"`
	MaxNotification int    `yaml:"max_notification"`
	WorkerNum       int    `yaml:"worker_num"`
	QueueNum        int    `yaml:"queue_num"`
	Mode            string `yaml:"mode"`
	SSL             bool   `yaml:"ssl"`
	CertPath        string `yaml:"cert_path"`
	KeyPath         string `yaml:"key_path"`
}

SectionCore is sub seciont of config.

type SectionIos

type SectionIos struct {
	Enabled     bool   `yaml:"enabled"`
	PemCertPath string `yaml:"pem_cert_path"`
	PemKeyPath  string `yaml:"pem_key_path"`
	Production  bool   `yaml:"production"`
}

SectionIos is sub seciont of config.

type SectionLog

type SectionLog struct {
	Format      string `yaml:"format"`
	AccessLog   string `yaml:"access_log"`
	AccessLevel string `yaml:"access_level"`
	ErrorLog    string `yaml:"error_log"`
	ErrorLevel  string `yaml:"error_level"`
}

SectionLog is sub seciont of config.

type SectionRedis

type SectionRedis struct {
	Addr     string `yaml:"addr"`
	Password string `yaml:"password"`
	DB       int64  `yaml:"db"`
}

SectionRedis is sub seciont of config.

type SectionStat

type SectionStat struct {
	Engine string        `yaml:"engine"`
	Redis  SectionRedis  `yaml:"redis"`
	BoltDB SectionBoltDB `yaml:"boltdb"`
}

SectionStat is sub seciont of config.

type StatusApp

type StatusApp struct {
	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

Jump to

Keyboard shortcuts

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