Send toast notifications using the Go API
masterTo send notifications within a Go application, use the gopkg.in/toast.v1 package. Create a toast.Notification struct and call its .Push() method.
Notification Fields:
AppID: The application identifier.Title: The notification title.Message: The notification body text.Icon: Path to an existing image file to use as an icon.Actions: A slice oftoast.Actionobjects to provide interactive buttons.
package main
import (
"log"
"gopkg.in/toast.v1"
)
func main() {
notification := toast.Notification{
AppID: "Example App",
Title: "My notification",
Message: "Some message about how important something is...",
Icon: "go.png", // This file must exist
Actions: []toast.Action{
{"protocol", "I'm a button", ""},
{"protocol", "Me too!", ""},
},
}
err := notification.Push()
if err != nil {
log.Fatalln(err)
}
}