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 ¶
var ErrInvalidDevice = errors.New("herald: invalid device")
ErrInvalidDevice is returned (wrapped) when a device or its quiet hours fail validation.
var ErrNotFound = errors.New("herald: device not found")
ErrNotFound is returned when a device does not exist for the app asked about.
Functions ¶
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 ¶
QuietHours is a daily window of local wall-clock time, "HH:MM" on a 24-hour clock.
func (QuietHours) Contains ¶
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. |