fcm

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 14 Imported by: 0

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

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

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

func (c *Client) Check(ctx context.Context) error

Check sends a validate-only message to a topic: credentials and project are checked, nothing is delivered.

func (*Client) Send

func (c *Client) Send(ctx context.Context, body []byte) (string, error)

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.

func (Config) Project

func (c Config) Project() string

Project is ProjectID, else the credentials' project_id.

func (Config) Validate

func (c Config) Validate() error

Validate checks what the schema cannot.

type TokenResult

type TokenResult struct {
	Token string `json:"token"`
	Error string `json:"error,omitempty"`
}

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.

Jump to

Keyboard shortcuts

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