package
0.0.12
Repository: https://github.com/m15t/gram.git
Documentation: pkg.go.dev

# README

AWS Simple Notification Service (SNS) wrapper

This package contains wrapper functions for SNS service to simplify the normal usages

Example

import (
  "fmt"
  snsutil "buuuksg/saas-api/internal/util/sns"
)

appArn := "put application arn here"
deviceToken := "put device token here"

// initialize the service with default configuration, using env vars for credentials
snsSvc := snsutil.New()

// register a new device
resp, err := snsSvc.RegisterDevice(appArn, deviceToken)
if err != nil {
  panic(fmt.Errorf("error creating sns endpoint: %+v", err))
}
// grab the arn
deviceArn := *resp.EndpointArn
fmt.Printf("generated sns arn: %s\n", deviceArn)

// sample data for push notification
datapayload := map[string]interface{}{
  "ghost": map[string]interface{}{
    "type":   "message type",
    "field1": "blah blah",
    "field2": "ok",
  },
}

// send the push notification to Android devices
output, err := snsSvc.SendToAndroid(deviceArn, snsutil.FCMPayload{Data: datapayload})
// or iOS devices
output, err = snsSvc.SendToIOS(deviceArn, snsutil.APNSPayload{Data: datapayload})

// or to all devices without knowing the OS
output, err = snsSvc.SendToDevice(deviceArn, snsutil.Message{
  APNS:        &snsutil.APNSPayload{Data: datapayload},
  APNSSandbox: &snsutil.APNSPayload{Data: datapayload},
  FCM:         &snsutil.FCMPayload{Data: datapayload},
})
if err != nil {
  panic(fmt.Errorf("error publishing message: %+v", err))
}
fmt.Printf("publish output: %+v\n", output)

// all done, to remove the device from SNS
_, err = snsSvc.DeregisterDevice(deviceArn)
if err != nil {
  panic(fmt.Errorf("error deregistering device : %+v", err))
}

# Functions

New initializes SNS service with default config.

# Structs

APNSAlert represents the APNS alert object.
APNSNotification represents the user-visible of the notification for APNS platform.
APNSPayload represents the APNS message payload.
FCMNotification represents the user-visible of the notification for FCM platform.
FCMPayload represents the FCM message payload.
Message represents the message structure for SNS message.
Service represents the snsutil service.