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 // The name of a sound file to play as an alert. Sound string // Content available is for silent notifications // with no alert, sound, or badge. ContentAvailable bool // Category identifier for custom actions in iOS 8 or newer. Category string // Mutable is used for Service Extensions introduced in iOS 10. MutableContent bool }
APS is Apple's reserved namespace. Use it for payloads destined to mobile devices (iOS).
Example ¶
package main import ( "encoding/json" "fmt" "github.com/RobotsAndPencils/buford/payload" "github.com/RobotsAndPencils/buford/payload/badge" ) func main() { p := payload.APS{ Alert: payload.Alert{Body: "Hello HTTP/2"}, Badge: badge.New(42), Sound: "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/RobotsAndPencils/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 ¶ added in v0.3.0
Validate that a payload has the correct fields.
Example ¶
package main import ( "fmt" "github.com/RobotsAndPencils/buford/payload" "github.com/RobotsAndPencils/buford/payload/badge" ) func main() { p := payload.APS{ Badge: badge.Preserve, Sound: "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"` // 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"` }
Alert dictionary.
type Browser ¶ added in v0.2.0
type Browser struct { Alert BrowserAlert URLArgs []string }
Browser for Safari Push Notifications.
Example ¶
package main import ( "encoding/json" "fmt" "github.com/RobotsAndPencils/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 ¶ added in v0.2.0
MarshalJSON allows you to json.Marshal(browser) directly.
type BrowserAlert ¶ added in v0.2.0
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.
Click to show internal directories.
Click to hide internal directories.