GoGo V4 Storage & Playback API Reference for Realtime Apps

Go to Channel Groups


 

These docs are for PubNub 4.0 for Go which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.0 for Go.

If you have questions about the PubNub for Go SDK, please contact us at support@pubnub.com.

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function fetches historical messages of a channel.
PubNub Storage/Playback Service provides real-time access to an unlimited history for all messages published to PubNub. Stored messages are replicated across multiple availability zones in several geographical data center locations. Stored messages can be encrypted with AES-256 message encryption ensuring that they are not readable while stored on PubNub's network.
It is possible to control how messages are returned and in what order, for example you can:
  • Search for messages starting on the newest end of the timeline (default behavior - Reverse = false)
  • Search for messages from the oldest end of the timeline by setting Reverse to true.
  • Page through results by providing a Start OR End time token.
  • Retrieve a slice of the time line by providing both a Start AND End time token.
  • Limit the number of messages to a specific quantity using the Count parameter.
 
Start & End parameter usage clarity:
If only the Start parameter is specified (without End), you will receive messages that are older than and up to that Start timetoken value.
If only the End parameter is specified (without Start) you will receive messages that match that End timetoken value and newer.
Specifying values for both Start and End parameters will return messages between those timetoken values (inclusive on the End value).
Keep in mind that you will still receive a maximum of 100 messages even if there are more messages that meet the timetoken values. Iterative calls to history adjusting the Start timetoken is necessary to page through the full set of results if more than 100 messages meet the timetoken values.
To run History you can use the following method(s) in the Go V4 SDK
  1. ParameterTypeRequiredDefaultDescription
    ChannelstringTrueSpecifies channel to return history messages from.
    ReverseboolOptionalfalseSetting to true will traverse the time line in reverse starting with the oldest message first.
    IncludeTimetokenboolOptionalfalseWhether event dates time tokens should be included in response or not.
    Startint64OptionalTime token delimiting the start of time slice (exclusive) to pull messages from.
    Endint64OptionalTime token delimiting the end of time slice (inclusive) to pull messages from.
    CountintOptionalSpecifies the number of historical messages to return.
    QueryParammap[string]stringOptionalnilQueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
Retrieve the last 100 messages on a channel:
res, status, err := pn.History().
    Channel("history_channel"). // where to fetch history from
    Count(2). // how many items to fetch
    Execute()

fmt.Println(res, status, err)
The History() operation returns a PNHistoryResult which contains the following operations:
MethodTypeDescription
Messages[]HistoryResponseItemarray of messages of type PNHistoryItemResult. See PNHistoryItemResult for more details.
StartTimetokenint64Start timetoken.
EndTimetokenint64End timetoken.
MethodTypeDescription
Timetokenint64Timetoken of the message
Entryinterface{}Message
  1. res, status, err := pn.History().
        Channel("my-ch"). // where to fetch history from
        Count(3). // how many items to fetch
        Reverse(true). // should go in reverse?
        Execute()
    for _, v := range res.Messages {
        fmt.Println(v.Entry) // custom JSON structure for message
    }
  2. res, status, err := pn.History().
        Channel("my-ch"). // where to fetch history from
        Start(int64(13847168620721752)). // first timestamp
        Reverse(true). // should go in reverse?
        Execute()
    for _, v := range res.Messages {
        fmt.Println(v.Entry) // custom JSON structure for message
    }
  3. res, status, err := pn.History().
        Channel("my-ch"). // where to fetch history from
        Count(100).
        Start(int64(-1)). // first timestamp
        End(int64(13847168819178600)). // last timestamp
        Reverse(true). // should go in reverse?
        Execute()
    for _, v := range res.Messages {
        fmt.Println(v.Entry) // custom JSON structure for message
    }
  4. func getAllMessages(startTT int64) {
    	res, _, _ := pn.History().
    		Channel("history_channel").
    		Count(2).
    		Execute()
    
    	msgs := res.Messages
    	start := res.StartTimetoken
    	end := res.EndTimetoken
    
    	if len(msgs) > 0 {
    		fmt.Println(len(msgs))
    		fmt.Println("start " + strconv.Itoa(int(start)))
    		fmt.Println("end " + strconv.Itoa(int(end)))
    	}
    
    	if len(msgs) == 100 {
    		getAllMessages(start)
    	}
    }
    
    getAllMessages(int64(14759343456292767))
  5. res, status, status := pn.History().
        Channel("history_channel").
        Count(100).
        IncludeTimetoken(true).
        Execute()
    
    fmt.Println(res, status, err)
Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function fetches historical messages of a channel.
PubNub Storage/Playback Service provides real-time access to an unlimited history for all messages published to PubNub. Stored messages are replicated across multiple availability zones in several geographical data center locations. Stored messages can be encrypted with AES-256 message encryption ensuring that they are not readable while stored on PubNub's network.
It is possible to control how messages are returned and in what order, for example you can:
  • Page through results by providing a Start OR End time token.
  • Retrieve a slice of the time line by providing both a Start AND End time token.
  • Limit the number of messages to a specific quantity using the Count() parameter.
Start & End parameter usage clarity:
If only the Start parameter is specified (without End), you will receive messages that are older than and up to that Start timetoken value.
If only the End parameter is specified (without Start) you will receive messages that match that End timetoken value and newer.
Specifying values for both Start and End parameters will return messages between those timetoken values (inclusive on the End value).
Keep in mind that you will still receive a maximum of 25 messages per channel even if there are more messages that meet the timetoken values.
To run Batch History you can use the following method(s) in the Go V4 SDK
  1. ParameterTypeRequiredDefaultsDescription
    ChannelsstringYesSpecifies channelsto return history messages.
    CountintOptional25Specifies the number of historical messages to return.

    Default/Maximum is 25 per channel.
    Startint64OptionalTime token delimiting the start of time slice (exclusive) to pull messages from.
    Endint64OptionalTime token delimiting the end of time slice (inclusive) to pull messages from.
    ReverseboolOptionalfalseSetting to true will traverse the time line in reverse starting with the oldest message first.
    QueryParammap[string]stringOptionalnilQueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
Retrieve the last 25 messages on a channel:
res, status, err := pn.Fetch().
		Channels([]string{"ch1", "ch2"}).
		Count(25).
		Reverse(true).
		Execute()
 
The batch history is limited to 500 channels and only the last 25 messages per channel.
MethodTypeDescription
Messageinterface{}Message from History.
Timetokenstring{{Timetoken}} of the message.
MethodType
Errorerror
CategoryStatusCategory
OperationOperationType
StatusCodeint
TLSEnabledbool
UUIDstring
AuthKeystring
Originstring
OriginalResponsestring
Requeststring
AffectedChannels[]string
AffectedChannelGroups[]string
Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Removes the messages from the history of a specific channel.
 
There is a setting to accept delete from history requests for a key, which you must enable by checking the Enable Delete-From-History checkbox in the key settings for your key in the Administration Portal.

Requires Initialization with secret key.

To Delete Messages from History you can use the following method(s) in the Go V4 SDK.
  1. ParameterTypeRequiredDescription
    ChannelstringYesSpecifies channels to delete messages from.
    Startint64OptionalTime token delimiting the start of time slice (inclusive) to delete messages from.
    Endint64OptionalTime token delimiting the end of time slice (exclusive) to delete messages from.
    QueryParammap[string]stringOptionalQueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
res, status, err := pn.DeleteMessages().
		Channel("ch").
		Start(int64(15343325214676133)).
		End(int64(15343325004275466)).
		Execute()
MethodType
Errorerror
CategoryStatusCategory
OperationOperationType
StatusCodeint
TLSEnabledbool
UUIDstring
AuthKeystring
Originstring
OriginalResponsestring
Requeststring
AffectedChannels[]string
AffectedChannelGroups[]string

  1. To delete a specific message, pass the publish timetoken (received from a successful publish) in the End parameter and timetoken +/- 1 in the Start parameter. e.g. if 15526611838554310 is the publish timetoken, pass 15526611838554309 in Start and 15526611838554310 in End parameters respectively as shown in the following code snippet.
    res, status, err := pn.DeleteMessages().
    		Channel("ch").
    		Start(int64(15526611838554309)).
    		End(int64(15526611838554310)).
    		Execute()
Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Returns the number of messages published on one or more channels since a given time. The count returned is the number of messages in history with a timetoken value greater than the passed value in the ChannelsTimetokenparameter.
 For keys with unlimited message retention enabled, this method considers only messages published in the last 7 days.
You can use the following method(s) in the Go V4 SDK:
  1. ParameterTypeRequiredDefaultsDescription
    Channels[]stringYesThe channels to fetch the message count
    ChannelsTimetoken[]int64YesnilArray of timetokens, in order of the channels list. Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens must be the same length as the list of channels, or the function returns a PNStatuswith an error flag.
    QueryParammap[string]stringOptionalnilQueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
res, status, err := pn.MessageCounts().
		Channels([]string{"ch1", "ch2"}).
		ChannelsTimetoken([]int64{1551795013294}).
		Execute()
The MessageCounts() operation returns a MessageCountsResponse object which contains the following operations:
MethodTypeDescription
Channelsmap[string]intA map of Channels with message count. Channels without messages have a count of 0. Channels with 10,000 messages or more have a count of 10000.
MethodType
Errorerror
CategoryStatusCategory
OperationOperationType
StatusCodeint
TLSEnabledbool
UUIDstring
AuthKeystring
Originstring
OriginalResponsestring
Requeststring
AffectedChannels[]string
AffectedChannelGroups[]string
  1. pn.MessageCounts().
    		Channels([]string{ch1, ch2}).
    		ChannelsTimetoken([]int64{1551795013294,155179501329433}).
    		Execute()

Go to Mobile Push