Documentation
¶
Overview ¶
Package fcm is the built-in push provider: FCM HTTP v1 per channel (a Firebase project) with OAuth2 from a service account, and topic subscriptions through the Instance ID API.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Check(ctx context.Context) error
- func (c *Client) Send(ctx context.Context, body []byte) (string, error)
- func (c *Client) Subscribe(ctx context.Context, topic string, tokens []string) ([]TokenResult, error)
- func (c *Client) Unsubscribe(ctx context.Context, topic string, tokens []string) ([]TokenResult, error)
- type Config
- type TokenResult
Constants ¶
const ( DefaultEndpoint = "https://fcm.googleapis.com" DefaultIIDEndpoint = "https://iid.googleapis.com" // MaxBatch is the most tokens one subscription call takes. MaxBatch = 1000 )
Endpoints of Google.
Variables ¶
var ErrConfig = errors.New("fcm: invalid channel")
ErrConfig is an invalid channel.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client of one channel.
func New ¶
func New(cfg Config, ts oauth2.TokenSource) (*Client, error)
New is the client of cfg; ts, when set, authorizes instead of the credentials (tests, a sidecar issuing tokens).
func (*Client) Check ¶
Check sends a validate-only message to a topic: credentials and project are checked, nothing is delivered.
func (*Client) Send ¶
Send posts an FCM v1 body and returns the message name; a refusal is a *provider.Error.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(ctx context.Context, topic string, tokens []string) ([]TokenResult, error)
Subscribe adds tokens (at most MaxBatch) to topic.
func (*Client) Unsubscribe ¶
func (c *Client) Unsubscribe(ctx context.Context, topic string, tokens []string) ([]TokenResult, error)
Unsubscribe removes tokens (at most MaxBatch) from topic.
type Config ¶
type Config struct {
// Credentials: the service account key JSON (Firebase Cloud Messaging
// API Admin).
Credentials config.Secret `json:"credentials" schemapb:"secret=true;description=Service account key JSON"`
// ProjectID; empty: the credentials' project_id.
ProjectID string `json:"project_id,omitempty" schemapb:"description=Firebase project, else the credentials' project"`
// Endpoint and IIDEndpoint: a test or a proxy may set others.
Endpoint string `json:"endpoint,omitempty" schemapb:"description=FCM endpoint, else fcm.googleapis.com"`
IIDEndpoint string `json:"iid_endpoint,omitempty" schemapb:"description=Instance ID endpoint, else iid.googleapis.com"`
}
Config of an FCM channel.
type TokenResult ¶
TokenResult is one token's outcome of a subscription call: empty Error when it worked.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fcmtest is a fake FCM endpoint for tests (HTTP v1 sends and Instance ID subscriptions): it records what it receives and answers by rules on the target.
|
Package fcmtest is a fake FCM endpoint for tests (HTTP v1 sends and Instance ID subscriptions): it records what it receives and answers by rules on the target. |