Send a push notification (Go)
Send a push notification via the Thinwrap Push facade in Go — one call shape for FCM, APNs, Expo and every other push provider.
1. Install
go get github.com/thinwrap/notifications-go2. Send the call
import "github.com/thinwrap/notifications-go"
p := notifications.NewPush(notifications.FcmConfig{
ProjectID: os.Getenv("FCM_PROJECT_ID"),
ClientEmail: os.Getenv("FCM_CLIENT_EMAIL"),
PrivateKey: os.Getenv("FCM_PRIVATE_KEY"),
})
res, err := p.Send(ctx, notifications.PushSendInput{
To: deviceToken,
Title: "Hello",
Body: "Hello from Thinwrap",
Data: map[string]string{"deepLink": "/orders/42"},
})
if err != nil {
var ce *notifications.ConnectorError
if errors.As(err, &ce) {
log.Printf("%s: %s", ce.ProviderCode, ce.ProviderMessage)
}
return
}
fmt.Println(res.Status, res.ProviderMessageID)
Same code works for all supported providers — just change the provider ID.