pushreceiver

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 24 Imported by: 1

README

go-push-receiver

GoDoc Go Report Card MIT License Github Actions

A library to subscribe to GCM/FCM and receive notifications.

This library was developed inspired by push-receiver (https://github.com/MatthieuLemoine/push-receiver/).

Build

  1. install protoc
brew install protobuf
  1. build
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ protoc -I=proto --go_out=pb/mcs proto/mcs.proto
$ protoc -I=proto --go_out=pb/checkin proto/checkin.proto
$ protoc -I=proto --go_out=pb/checkin proto/android_checkin.proto
$ go build

License

MIT License

proto file is licensed by is The Chromium Authors. (BSD-style license) (copied it from https://chromium.googlesource.com/chromium/chromium/+/trunk/google_apis/gcm/protocol/)

Documentation

Overview

Package pushreceiver is Push Message Receiver library from FCM.

Index

Constants

This section is empty.

Variables

View Source
var ErrFcmNotEnoughData = errors.New("data Enough from FCM")

ErrFcmNotEnoughData is error that data is not enough data from FCM.

View Source
var ErrGcmAuthorization = errors.New("GCM authorization error")

ErrGcmAuthorization is authorization error of GCM.

View Source
var ErrNotFoundInAppData = errors.New("key not found")

ErrNotFoundInAppData is error that key not found in app data.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// contains filtered or unexported fields
}

Backoff with jitter sleep to prevent overloaded conditions during intervals https://www.awsarchitectureblog.com/2015/03/backoff.html

func NewBackoff

func NewBackoff(base time.Duration, max time.Duration) *Backoff

NewBackoff creates Backoff instance.

type Client

type Client struct {
	Events chan Event
	// contains filtered or unexported fields
}

Client is FCM Push receive client.

func New

func New(senderID string, options ...ClientOption) *Client

New returns a new FCM push receive client instance.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context)

Subscribe subscribe to FCM.

type ClientOption

type ClientOption func(*Client)

ClientOption type

func WithBackoff

func WithBackoff(b *Backoff) ClientOption

WithBackoff is Backoff setter

func WithCreds

func WithCreds(creds *FCMCredentials) ClientOption

WithCreds is credentials setter

func WithDialer

func WithDialer(dialer *net.Dialer) ClientOption

WithDialer is net.Dialer setter

func WithHTTPClient

func WithHTTPClient(c httpClient) ClientOption

WithHTTPClient is http.Client setter

func WithHeartbeat

func WithHeartbeat(options ...HeartbeatOption) ClientOption

WithHeartbeat is Heartbeat setter

func WithLogger

func WithLogger(logger logger) ClientOption

WithLogger is logger setter

func WithReceivedPersistentID

func WithReceivedPersistentID(ids []string) ClientOption

WithReceivedPersistentID is received persistentId list setter

func WithRetry

func WithRetry(retry bool) ClientOption

WithRetry configures whether to retry when an error occurs.

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ClientOption

WithTLSConfig is tls.Config setter

type ConnectedEvent

type ConnectedEvent struct {
	ServerTimestamp int64
}

ConnectedEvent is connection event.

type DisconnectedEvent

type DisconnectedEvent struct {
	ErrorObj error
}

DisconnectedEvent is disconnect event.

type Event

type Event interface{}

Event type.

type FCMCredentials

type FCMCredentials struct {
	AppID         string `json:"appId"`
	AndroidID     uint64 `json:"androidId"`
	SecurityToken uint64 `json:"securityToken"`
	Token         string `json:"token"`
	PrivateKey    []byte `json:"privateKey"`
	PublicKey     []byte `json:"publicKey"`
	AuthSecret    []byte `json:"authSecret"`
}

FCMCredentials is Credentials for FCM

type Heartbeat

type Heartbeat struct {
	// contains filtered or unexported fields
}

Heartbeat sends signal for connection keep alive.

type HeartbeatError

type HeartbeatError struct {
	ErrorObj error
}

HeartbeatError is send heartbeat error.

type HeartbeatEvent

type HeartbeatEvent struct {
	Send                 bool
	Ack                  bool
	Status               int64
	LastStreamIDReceived int32
}

HeartbeatEvent is send/received heartbeat event.

type HeartbeatOption

type HeartbeatOption func(*Heartbeat)

HeartbeatOption type

func WithAdaptive

func WithAdaptive(enabled bool) HeartbeatOption

WithAdaptive is heartbeat adaptive setter

func WithClientInterval

func WithClientInterval(interval time.Duration) HeartbeatOption

WithClientInterval is heartbeat client interval setter

func WithDeadmanTimeout

func WithDeadmanTimeout(timeout time.Duration) HeartbeatOption

WithDeadmanTimeout is heartbeat deadman timeout setter

func WithServerInterval

func WithServerInterval(interval time.Duration) HeartbeatOption

WithServerInterval is heartbeat server interval setter

type MessageEvent

type MessageEvent struct {
	PersistentID string `json:"persistentId"`
	From         string `json:"from"`
	To           string `json:"to"`
	TTL          int32  `json:"ttl"`
	Sent         int64  `json:"sent"`
	Data         []byte `json:"data"`
}

MessageEvent is receive message event.

type RetryEvent

type RetryEvent struct {
	ErrorObj   error
	RetryAfter time.Duration
}

RetryEvent is disconnect event.

type UnauthorizedError

type UnauthorizedError struct {
	ErrorObj error
}

UnauthorizedError is unauthorization error.

type UpdateCredentialsEvent

type UpdateCredentialsEvent struct {
	Credentials *FCMCredentials
}

UpdateCredentialsEvent is credentials update event.

Directories

Path Synopsis
examples
pb
mcs

Jump to

Keyboard shortcuts

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