Documentation
¶
Overview ¶
Package push receives notifications from your server: APNs on iOS, Firebase Cloud Messaging on Android, and Web Push in a browser.
nimbus native plugin add push
Android needs your Firebase project's google-services.json, at native/android/app/google-services.json. On iOS, turn on Push Notifications for the app in your Apple developer account. The web needs a VAPID key pair (see NewVAPIDKeys), and your server sends to browsers with SendWeb.
ok, err := push.Request(ctx)
t, err := push.GetToken(ctx)
// send t.Value and t.Service to your server
go push.Watch(ctx, func(m push.Message) { openOrder(m.Data["order"]) })
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGone = errors.New("push: subscription expired or unsubscribed")
ErrGone is the browser having unsubscribed: delete the token.
var VAPID = Keys{ Public: os.Getenv("NIMBUS_VAPID_PUBLIC"), Private: os.Getenv("NIMBUS_VAPID_PRIVATE"), Subject: os.Getenv("NIMBUS_VAPID_SUBJECT"), }
VAPID is the key pair GetToken and SendWeb use, from NIMBUS_VAPID_PUBLIC, NIMBUS_VAPID_PRIVATE and NIMBUS_VAPID_SUBJECT unless you set it.
Functions ¶
Types ¶
type Keys ¶ added in v0.0.14
type Keys struct {
Public string // base64url; the browser subscribes with it
Private string // base64url; keep it on your server
Subject string // "mailto:you@example.com" or your site's https address, for push services to reach you
}
Keys is a VAPID key pair: it tells browsers' push services that a message comes from your server. Make one with NewVAPIDKeys, once, and keep it; a new pair orphans every browser that subscribed with the old one.
func NewVAPIDKeys ¶ added in v0.0.14
NewVAPIDKeys makes a key pair for the web. Run it once and store the pair as NIMBUS_VAPID_PUBLIC and NIMBUS_VAPID_PRIVATE.
type Message ¶
type Message struct {
Title string `json:"title"` // its heading
Body string `json:"body"` // its text
Data map[string]string `json:"data"` // what your server sent with it
Tapped bool `json:"tapped"` // whether they tapped it to get here
}
Message is a notification that arrived while the app was open, or one that was tapped.
type Notification ¶ added in v0.0.14
type Notification struct {
Title string `json:"title"` // its heading
Body string `json:"body"` // its text
Data map[string]string `json:"data,omitempty"` // Message.Data on arrival
URL string `json:"url,omitempty"` // the page a tap opens, such as "/orders/42"; "/" by default
Tag string `json:"tag,omitempty"` // a new one with the same tag replaces the old
TTL time.Duration `json:"-"` // how long the push service keeps trying (default a day)
}
Notification is what SendWeb shows.
type Token ¶
type Token struct {
Value string `json:"value"` // send this to your server
Service string `json:"service"` // "apns", "fcm" or "web"
}
Token is where your server sends to reach this phone.