Documentation
¶
Overview ¶
Package payload prepares a JSON payload to push.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrIncomplete = errors.New("payload does not contain necessary fields")
)
Validation errors.
Functions ¶
This section is empty.
Types ¶
type APS ¶
type APS struct { // Alert dictionary. Alert Alert // Badge to display on the app icon. // Set to badge.Preserve (default), badge.Clear // or a specific value with badge.New(n). Badge badge.Badge // Details how to play alert. Sound Sound // Thread identifier to create notification groups in iOS 12 or newer. ThreadID string // Category identifier for custom actions in iOS 8 or newer. Category string // Content available is for silent notifications // with no alert, sound, or badge. ContentAvailable bool // Mutable is used for Service Extensions introduced in iOS 10. MutableContent bool // Content identifier. TargetContentID string // URL arguments for Safari pushes: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html#//apple_ref/doc/uid/TP40013225-CH3-SW17 SafariURLArgs []string InterruptionLevel InterruptionLevel RelevanceScore float32 }
APS is Apple's reserved namespace. Use it for payloads destined to mobile devices (iOS).
Example ¶
package main import ( "encoding/json" "fmt" "github.com/alexei-g-aloteq/buford/payload" "github.com/alexei-g-aloteq/buford/payload/badge" ) func main() { p := payload.APS{ Alert: payload.Alert{Body: "Hello HTTP/2"}, Badge: badge.New(42), Sound: payload.Sound{SoundName: "bingbong.aiff"}, } b, err := json.Marshal(p) if err != nil { // handle error } fmt.Printf("%s", b) }
Output: {"aps":{"alert":"Hello HTTP/2","badge":42,"sound":"bingbong.aiff"}}
func (*APS) Map ¶
Map returns the payload as a map that you can customize before serializing it to JSON.
Example ¶
Use Map to add custom values to the payload.
package main import ( "encoding/json" "fmt" "github.com/alexei-g-aloteq/buford/payload" ) func main() { p := payload.APS{ Alert: payload.Alert{Body: "Topic secret message"}, } pm := p.Map() pm["acme2"] = []string{"bang", "whiz"} b, err := json.Marshal(pm) if err != nil { // handle error } fmt.Printf("%s", b) }
Output: {"acme2":["bang","whiz"],"aps":{"alert":"Topic secret message"}}
func (APS) MarshalJSON ¶
MarshalJSON allows you to json.Marshal(aps) directly.
func (*APS) Validate ¶
Validate that a payload has the correct fields.
Example ¶
package main import ( "fmt" "github.com/alexei-g-aloteq/buford/payload" "github.com/alexei-g-aloteq/buford/payload/badge" ) func main() { p := payload.APS{ Badge: badge.Preserve, Sound: payload.Sound{SoundName: "bingbong.aiff"}, } if err := p.Validate(); err != nil { fmt.Println(err) } }
Output: payload does not contain necessary fields
type Alert ¶
type Alert struct { // Title is a short string shown briefly on Apple Watch in iOS 8.2 or newer. Title string `json:"title,omitempty"` TitleLocKey string `json:"title-loc-key,omitempty"` TitleLocArgs []string `json:"title-loc-args,omitempty"` // Subtitle added in iOS 10 Subtitle string `json:"subtitle,omitempty"` SubtitleLocKey string `json:"subtitle-loc-key,omitempty"` SubtitleLocArgs []string `json:"subtitle-loc-args,omitempty"` // Body text of the alert message. Body string `json:"body,omitempty"` LocKey string `json:"loc-key,omitempty"` LocArgs []string `json:"loc-args,omitempty"` // Key for localized string for "View" button. ActionLocKey string `json:"action-loc-key,omitempty"` // Image file to be used when user taps or slides the action button. LaunchImage string `json:"launch-image,omitempty"` // String for "View" button on Safari. SafariAction string `json:"action,omitempty"` }
Alert dictionary.
type Browser ¶
type Browser struct { Alert BrowserAlert URLArgs []string }
Browser for Safari Push Notifications.
Example ¶
package main import ( "encoding/json" "fmt" "github.com/alexei-g-aloteq/buford/payload" ) func main() { p := payload.Browser{ Alert: payload.BrowserAlert{ Title: "Flight A998 Now Boarding", Body: "Boarding has begun for Flight A998.", Action: "View", }, URLArgs: []string{"boarding", "A998"}, } b, err := json.Marshal(p) if err != nil { // handle error } fmt.Printf("%s", b) }
Output: {"aps":{"alert":{"title":"Flight A998 Now Boarding","body":"Boarding has begun for Flight A998.","action":"View"},"url-args":["boarding","A998"]}}
func (Browser) MarshalJSON ¶
MarshalJSON allows you to json.Marshal(browser) directly.
type BrowserAlert ¶
type BrowserAlert struct { // Title and Body are required Title string `json:"title"` Body string `json:"body"` // Action button label (defaults to "Show") Action string `json:"action,omitempty"` }
BrowserAlert for Safari Push Notifications.
type InterruptionLevel ¶ added in v0.16.0
type InterruptionLevel string
const ( InterruptionLevelPassive InterruptionLevel = "passive" InterruptionLevelActive InterruptionLevel = "active" InterruptionLevelTimeSensitive InterruptionLevel = "time-sensitive" InterruptionLevelCritical InterruptionLevel = "critical" )
Click to show internal directories.
Click to hide internal directories.