Utility Methods API for Go SDK

The methods on this page are utility methods that don't fit into other categories.

Time

This function will return a 17 digit precision Unix epoch.

Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000

Example of creating a timetoken for a specific time and date:

08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000

Method(s)

To fetch Time you can use the following method(s) in Go SDK:

pn.Time().
QueryParam(queryParam).
Execute()
* required
ParameterDescription
QueryParam
Type: map[string]string
QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.

Sample code

Get PubNub timetoken

res, status, err := pn.Time().Execute()

fmt.Println(res, status, err)

Response

MethodDescription
Timetoken
Type: int64
Returns a date representation of current timetoken.

Create push payload

This method creates the push payload for use in the appropriate endpoint calls.

Method(s)

CreatePushPayload().
SetAPNSPayload(pubnub.PNAPNSData,[]pubnub.PNAPNS2Data).
SetCommonPayload(map[string]interface{}).
SetFCMPayload(pubnub.PNFCMData).
BuildPayload()
* required
ParameterDescription
SetAPNSPayload
Type: pubnub.PNAPNSData
Set APNS Payload. Associated APNS devices will receive only the data within the pn_apns key.
SetAPNSPayload
Type: []pubnub.PNAPNS2Data
Set APNS2 Payload. Associated APNS devices will receive only the data within the pn_push key.
SetFCMPayload
Type: pubnub.PNFCMData
Set FCM Payload. Associated FCM devices will receive only the data within the pn_gcm key.
SetCommonPayload
Type: map[string]interface
Set Common Payload. Native PubNub subscribers will receive the entire object literal, including the pn_apns, pn_gcm, and common payload.
BuildPayload *
Type:
Builds the payload from the values set using the parameters. Returns a map[string]interface{}

Sample code

Create push payload

aps := pubnub.PNAPSData{
Alert: "apns alert",
Badge: 1,
Sound: "ding",
Custom: map[string]interface{}{
"aps_key1": "aps_value1",
"aps_key2": "aps_value2",
},
}

apns := pubnub.PNAPNSData{
APS: aps,
Custom: map[string]interface{}{
"apns_key1": "apns_value1",
"apns_key2": "apns_value2",
show all 82 lines

Response

The CreatePushPayload() operation returns a map[string]interface{} which can be passed directly to the Publish Method's Message parameter.

Last updated on