gaurun

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 32 Imported by: 7

Documentation

Index

Constants

View Source
const (
	PlatFormIos = iota + 1
	PlatFormAndroid
)
View Source
const (
	StatusAcceptedPush  = "accepted-push"
	StatusSucceededPush = "succeeded-push"
	StatusFailedPush    = "failed-push"
	StatusDisabledPush  = "disabled-push"
)
View Source
const (
	ApnsPushTypeAlert      = "alert"
	ApnsPushTypeBackground = "background"
)
View Source
const (
	Version = "0.14.0"
)

Variables

View Source
var (
	// Toml configuration for Gaurun
	ConfGaurun ConfToml
	// push notification Queue
	QueueNotification chan RequestGaurunNotification
	// Stat for Gaurun
	StatGaurun StatApp
	// http client for APNs and GCM/FCM
	APNSClient APNsClient
	GCMClient  *gcm.Client
	// access and error logger
	LogAccess *zap.Logger
	LogError  *zap.Logger
	// sequence ID for numbering push
	SeqID uint64
)
View Source
var (
	// PusherCountAll is the shared value between workers
	PusherCountAll int64

	// PusherWg is global wait group for pusher worker.
	// It increments when new pusher is swapned and decrements when job is done.
	//
	// This is used to block main process to shutdown while pusher is still working.
	PusherWg sync.WaitGroup
)

Functions

func ApnsPushHttp2 added in v0.5.0

func ApnsPushHttp2(token string, service *push.Service, headers *push.Headers, payload map[string]interface{}) error

func ConfigPushersHandler added in v0.7.0

func ConfigPushersHandler(w http.ResponseWriter, r *http.Request)

func InitAPNSClient added in v0.8.0

func InitAPNSClient() error

func InitGCMClient added in v0.2.1

func InitGCMClient() error

InitGCMClient initializes GCMClient which is globally declared.

func InitStat added in v0.5.1

func InitStat()

func LocalTimeEncoder added in v0.8.0

func LocalTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func LogAcceptedRequest

func LogAcceptedRequest(r *http.Request)

func LogPush

func LogPush(id uint64, status, token string, ptime float64, req RequestGaurunNotification, errPush error)

func LogSetupFatal added in v0.7.0

func LogSetupFatal(err error)

LogSetupFatal output error log with log package and exit immediately.

func NewApnsHeadersHttp2 added in v0.5.0

func NewApnsHeadersHttp2(req *RequestGaurunNotification) *push.Headers

func NewApnsHeadersHttp2WithToken added in v0.13.0

func NewApnsHeadersHttp2WithToken(req *RequestGaurunNotification, t *token.Token) *push.Headers

func NewApnsPayloadHttp2 added in v0.5.0

func NewApnsPayloadHttp2(req *RequestGaurunNotification) map[string]interface{}

func NewApnsServiceHttp2 added in v0.5.0

func NewApnsServiceHttp2(apnsClient APNsClient) *push.Service

func NewTransportHttp2 added in v0.5.1

func NewTransportHttp2(cert tls.Certificate) (*http.Transport, error)

func PrintVersion added in v0.5.1

func PrintVersion()

func PushNotificationHandler

func PushNotificationHandler(w http.ResponseWriter, r *http.Request)

func RegisterHandlers added in v0.8.0

func RegisterHandlers(mux *http.ServeMux)

func RunServer added in v0.8.0

func RunServer(server *http.Server, conf *ConfToml) error

func StartPushWorkers

func StartPushWorkers(workerNum, queueNum int64)

func StatsHandler added in v0.5.1

func StatsHandler(w http.ResponseWriter, r *http.Request)

Types

type APNsClient added in v0.13.0

type APNsClient struct {
	HTTPClient *http.Client
	// Token is set only for token-based provider connection trust
	Token *token.Token
}

func NewApnsClientHttp2 added in v0.5.0

func NewApnsClientHttp2(certPath, keyPath, keyPassphrase string) (APNsClient, error)

func NewApnsClientHttp2ForToken added in v0.13.0

func NewApnsClientHttp2ForToken(authKey *ecdsa.PrivateKey, keyID, teamID string) (APNsClient, error)

type CertificatePem

type CertificatePem struct {
	Cert []byte
	Key  []byte
}

type ConfToml

type ConfToml struct {
	Core    SectionCore    `toml:"core"`
	Android SectionAndroid `toml:"android"`
	Ios     SectionIos     `toml:"ios"`
	Log     SectionLog     `toml:"log"`
}

func BuildDefaultConf added in v0.5.1

func BuildDefaultConf() ConfToml

func LoadConf added in v0.5.1

func LoadConf(confGaurun ConfToml, confPath string) (ConfToml, error)

type ExtendJSON added in v0.3.0

type ExtendJSON struct {
	Key   string `json:"key"`
	Value string `json:"val"`
}

type LogPushEntry

type LogPushEntry struct {
	Type     string  `json:"type"`
	Time     string  `json:"time"`
	ID       uint64  `json:"id"`
	Platform string  `json:"platform"`
	Token    string  `json:"token"`
	Message  string  `json:"message"`
	Ptime    float64 `json:"ptime"`
	Error    string  `json:"error"`
	// Android
	CollapseKey    string `json:"collapse_key,omitempty"`
	DelayWhileIdle bool   `json:"delay_while_idle,omitempty"`
	TimeToLive     int    `json:"time_to_live,omitempty"`
	// iOS
	Title            string `json:"title,omitempty"`
	Subtitle         string `json:"subtitle,omitempty"`
	Badge            int    `json:"badge,omitempty"`
	Category         string `json:"category,omitempty"`
	Sound            string `json:"sound,omitempty"`
	ContentAvailable bool   `json:"content_available,omitempty"`
	MutableContent   bool   `json:"mutable_content,omitempty"`
	Expiry           int    `json:"expiry,omitempty"`
}

type LogReq

type LogReq struct {
	Type          string `json:"type"`
	Time          string `json:"time"`
	URI           string `json:"uri"`
	Method        string `json:"method"`
	Proto         string `json:"proto"`
	ContentLength int64  `json:"content_length"`
}

type Reopener added in v0.7.1

type Reopener interface {
	Reopen() error
}

func InitLog

func InitLog(outString, levelString string) (*zap.Logger, Reopener, error)

type RequestGaurun

type RequestGaurun struct {
	Notifications []RequestGaurunNotification `json:"notifications"`
}

type RequestGaurunNotification

type RequestGaurunNotification struct {
	// Common
	Tokens     []string `json:"token"`
	Platform   int      `json:"platform"`
	Message    string   `json:"message"`
	Identifier string   `json:"identifier,omitempty"`
	// Android
	CollapseKey    string `json:"collapse_key,omitempty"`
	DelayWhileIdle bool   `json:"delay_while_idle,omitempty"`
	TimeToLive     int    `json:"time_to_live,omitempty"`
	Priority       string `json:"priority,omitempty"`
	// iOS
	Title            string       `json:"title,omitempty"`
	Subtitle         string       `json:"subtitle,omitempty"`
	PushType         string       `json:"push_type,omitempty"`
	Badge            int          `json:"badge,omitempty"`
	Category         string       `json:"category,omitempty"`
	Sound            string       `json:"sound,omitempty"`
	ContentAvailable bool         `json:"content_available,omitempty"`
	MutableContent   bool         `json:"mutable_content,omitempty"`
	Expiry           int          `json:"expiry,omitempty"`
	Retry            int          `json:"retry,omitempty"`
	Extend           []ExtendJSON `json:"extend,omitempty"`
	// meta
	ID uint64 `json:"seq_id,omitempty"`
}

type ResponseGaurun

type ResponseGaurun struct {
	Message string `json:"message"`
}

type SectionAndroid

type SectionAndroid struct {
	Enabled          bool   `toml:"enabled"`
	ApiKey           string `toml:"apikey"`
	Timeout          int    `toml:"timeout"`
	KeepAliveTimeout int    `toml:"keepalive_timeout"`
	KeepAliveConns   int    `toml:"keepalive_conns"`
	RetryMax         int    `toml:"retry_max"`
}

type SectionCore

type SectionCore struct {
	Port               string `toml:"port"`
	WorkerNum          int64  `toml:"workers"`
	QueueNum           int64  `toml:"queues"`
	NotificationMax    int64  `toml:"notification_max"`
	PusherMax          int64  `toml:"pusher_max"`
	ShutdownTimeout    int64  `toml:"shutdown_timeout"`
	Pid                string `toml:"pid"`
	AllowsEmptyMessage bool   `toml:"allows_empty_message"`
}

type SectionIos

type SectionIos struct {
	Enabled          bool   `toml:"enabled"`
	PemCertPath      string `toml:"pem_cert_path"`
	PemKeyPath       string `toml:"pem_key_path"`
	PemKeyPassphrase string `toml:"pem_key_passphrase"`
	TokenAuthKeyPath string `toml:"token_auth_key_path"`
	TokenAuthKeyID   string `toml:"token_auth_key_id"`
	TokenAuthTeamID  string `toml:"token_auth_team_id"`
	Sandbox          bool   `toml:"sandbox"`
	RetryMax         int    `toml:"retry_max"`
	Timeout          int    `toml:"timeout"`
	KeepAliveTimeout int    `toml:"keepalive_timeout"`
	KeepAliveConns   int    `toml:"keepalive_conns"`
	Topic            string `toml:"topic"`
}

func (*SectionIos) IsCertificateBasedProvider added in v0.13.0

func (s *SectionIos) IsCertificateBasedProvider() bool

func (*SectionIos) IsTokenBasedProvider added in v0.13.0

func (s *SectionIos) IsTokenBasedProvider() bool

type SectionLog

type SectionLog struct {
	AccessLog string `toml:"access_log"`
	ErrorLog  string `toml:"error_log"`
	Level     string `toml:"level"`
}

type StatAndroid

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

type StatApp

type StatApp struct {
	QueueMax    int         `json:"queue_max"`
	QueueUsage  int         `json:"queue_usage"`
	PusherMax   int64       `json:"pusher_max"`
	PusherCount int64       `json:"pusher_count"`
	Ios         StatIos     `json:"ios"`
	Android     StatAndroid `json:"android"`
}

type StatIos

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

Jump to

Keyboard shortcuts

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