Go Server SDK

Installation

You can install this SDK by doing:

bash

1
$ go get github.com/pusher/push-notifications-go

Usage

Configuring the SDK for Your Instance

Use your instance id and secret key (you can get these from the dashboard) to create a PushNotifications instance:

Go

1
2
3
4
5
6
const (
  instanceId = "YOUR_INSTANCE_ID_HERE"
  secretKey  = "YOUR_SECRET_KEY_HERE"
)

notifications := pushnotifications.New(instanceId, secretKey)

Publishing a Notification

Once you have created your PushNotifications instance you can publish a push notification to your registered and subscribed devices:

Go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
publishRequest := map[string]interface{}{
  "apns": map[string]interface{}{
    "aps": map[string]interface{}{
      "alert": map[string]interface{}{
        "title": "Hello",
        "body":  "Hello, world",
      },
    },
  },
  "fcm": map[string]interface{}{
    "notification": map[string]interface{}{
      "title": "Hello",
      "body":  "Hello, world",
    },
  },
}

pubId, err := notifications.Publish([]string{"hello"}, publishRequest)
if err != nil {
  fmt.Println(err)
} else {
  fmt.Println("Publish Id:", pubId)
}

Reference

pushnotifications.New(instanceId, secretKey)

Arguments

  • instanceId(string): The unique identifier for your Push notifications instance. This can be found in the dashboard under "keys".
  • secretKey(string): The secret key your server will use to access your Beams instance. This can be found in the dashboard under "keys".

Returns
A Beams instance.


pushnotifications.Publish(interests, publishRequest)

Arguments

  • interests ([]string): List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Interests.
  • publishRequest (map[string]interface{}) A map containing the publish request body. See publish API reference.

Returns
A non-empty `publishId` string if successful; or a non-nil `error` otherwise.

Did you find this document useful?

We are always striving to create the most accurate and informative docs as possible. If there is something especially wrong (or right) here then please let us know.