device

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package device defines the registry of devices a user receives push notifications on, and the store every backend implements for it.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDevice = errors.New("herald: invalid device")

ErrInvalidDevice is returned (wrapped) when a device or its quiet hours fail validation.

View Source
var ErrNotFound = errors.New("herald: device not found")

ErrNotFound is returned when a device does not exist for the app asked about.

Functions

func UniqueKey

func UniqueKey(d *Device) string

UniqueKey is the identity a device is upserted on within an app and user: the public key when it has one, else the address.

Types

type Device

type Device struct {
	ID         string            `json:"id"`
	AppID      string            `json:"app_id"`
	UserID     string            `json:"user_id"`
	Channel    string            `json:"channel"`  // "push"
	Provider   string            `json:"provider"` // driver name, e.g. "sealed"
	Address    string            `json:"address"`  // platform token, or gateway handle for "sealed"
	PublicKey  []byte            `json:"public_key,omitempty"`
	Platform   string            `json:"platform"` // "android" | "ios"
	Name       string            `json:"name,omitempty"`
	Locale     string            `json:"locale,omitempty"`
	TimeZone   string            `json:"time_zone,omitempty"` // IANA name
	QuietHours *QuietHours       `json:"quiet_hours,omitempty"`
	Settings   map[string]string `json:"settings,omitempty"` // owned by the application, opaque to Herald
	LastSeenAt time.Time         `json:"last_seen_at"`
	CreatedAt  time.Time         `json:"created_at"`
	UpdatedAt  time.Time         `json:"updated_at"`
}

Device is one registered push destination for a user.

type QuietHours

type QuietHours struct {
	Start string `json:"start"`
	End   string `json:"end"`
}

QuietHours is a daily window of local wall-clock time, "HH:MM" on a 24-hour clock.

func (QuietHours) Contains

func (q QuietHours) Contains(t time.Time, loc *time.Location) bool

Contains reports whether t falls in [Start, End) on local wall-clock minutes in loc (UTC when nil). An End before Start wraps midnight. Start equal to End, or a value that does not parse, means never.

func (QuietHours) Validate

func (q QuietHours) Validate() error

Validate checks that both ends are "HH:MM" between 00:00 and 23:59.

type Store

type Store interface {
	// SaveDevice upserts on (AppID, UserID, UniqueKey). An insert assigns ID and
	// CreatedAt. A conflict overwrites every other field but keeps the stored ID
	// and CreatedAt. Both are written back into d. The store may set UpdatedAt.
	SaveDevice(ctx context.Context, d *Device) error
	// GetDevice returns ErrNotFound for a missing device or another app's device.
	GetDevice(ctx context.Context, appID, id string) (*Device, error)
	// ListDevices returns a user's devices ordered by CreatedAt, then ID.
	ListDevices(ctx context.Context, appID, userID string) ([]*Device, error)
	// DeleteDevice returns ErrNotFound when no such device exists.
	DeleteDevice(ctx context.Context, appID, id string) error
	// DeleteUserDevices removes every device of a user. None is not an error.
	DeleteUserDevices(ctx context.Context, appID, userID string) error
}

Store persists devices.

Directories

Path Synopsis
Package devicetest is the conformance suite every device.Store backend runs.
Package devicetest is the conformance suite every device.Store backend runs.

Jump to

Keyboard shortcuts

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