messaging

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

messaging — Firebase Cloud Messaging client

import "github.com/downsized-devs/sdk-go/messaging"

Stability: Stable. See STABILITY.md.

Push notifications via Firebase Cloud Messaging (FCM). Manages device-token topic subscriptions and broadcasts.

Features

  • SubscribeToTopic, UnsubscribeFromTopic
  • BroadcastToTopic — send a data payload to every device on a topic.
  • BatchSendDryRun — validate token batches without delivering; chunked to MaximumTokensPerBatch (500) per call.

Installation

go get github.com/downsized-devs/sdk-go/messaging

Quick Start

m := messaging.Init(messaging.Config{
    Firebase: messaging.FirebaseConf{
        AccountKey: messaging.FirebaseAccountKey{ /* ... */ },
    },
}, log, jsonParser, nil) // httpClient is deprecated; pass nil

_ = m.SubscribeToTopic(ctx, "deviceToken1", "news")
_ = m.BroadcastToTopic(ctx, "news", map[string]string{
    "title": "Daily update",
    "body":  "...body...",
})

API Reference

Symbol Signature
Init func Init(cfg Config, log logger.Interface, json parser.JsonInterface, _ *http.Client) Interface
Interface.SubscribeToTopic (ctx, deviceToken string, topic string) error
Interface.UnsubscribeFromTopic (ctx, deviceToken string, topic string) error
Interface.BroadcastToTopic (ctx, topic string, payload map[string]string) error
Interface.BatchSendDryRun (ctx, tokens []string) ([]string, error)

The httpClient argument to Init is accepted for backwards-compatibility but ignored — see the GoDoc for the Deprecated: notice.

Configuration

Firebase.AccountKey — full Firebase service-account JSON, loaded from secrets.

Dependencies

  • Internal: logger, parser
  • External: firebase.google.com/go, firebase.google.com/go/messaging, google.golang.org/api/option

Testing

Unit tests cover the public surface using a firebaseMessenger seam; no network calls are made.

go test ./messaging/...

Contributing

See CONTRIBUTING.md.

  • auth — also uses Firebase; share service-account loading if practical.
  • parser — for marshalling FCM payloads.

Documentation

Overview

Package messaging is a thin wrapper over Firebase Cloud Messaging (FCM). It exposes topic subscription management, single-topic broadcasts, and a dry-run helper for validating large batches of device tokens.

Index

Constants

View Source
const (
	MaximumTokensPerBatch = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SkipFirebaseInit bool
	Firebase         FirebaseConf
}

Config controls how Init builds the messaging client. Setting SkipFirebaseInit short-circuits the live Firebase Cloud Messaging connection — useful for tests.

type FirebaseAccountKey

type FirebaseAccountKey struct {
	Type                    string `json:"type"`
	ProjectID               string `json:"project_id"`
	PrivateKeyID            string `json:"private_key_id"`
	PrivateKey              string `json:"private_key"`
	ClientEmail             string `json:"client_email"`
	ClientID                string `json:"client_id"`
	AuthURI                 string `json:"auth_uri"`
	TokenURI                string `json:"token_uri"`
	AuthProviderx509CertURL string `json:"auth_provider_x509_cert_url"`
	Clientx509CertURL       string `json:"client_x509_cert_url"`
}

type FirebaseConf

type FirebaseConf struct {
	AccountKey FirebaseAccountKey
	ApiKey     string
}

type Interface

type Interface interface {
	SubscribeToTopic(ctx context.Context, deviceToken, topic string) error
	UnsubscribeFromTopic(ctx context.Context, deviceToken, topic string) error
	BroadcastToTopic(ctx context.Context, topic string, payload map[string]string) error
	BatchSendDryRun(ctx context.Context, tokens []string) ([]string, error)
}

Interface is the public surface of the messaging package — mockable for tests via the firebaseMessenger seam underneath.

func Init deprecated

Init builds a messaging client. The httpClient parameter is ignored because the underlying Firebase SDK manages its own HTTP transport.

Deprecated: httpClient is not used and will be removed in v2.0.0. Pass nil for forward-compatibility.

Jump to

Keyboard shortcuts

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