App Context API for Go SDK

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is changed: set, updated, or removed from the database. At the same time, making a request to set the same data that already exist, doesn't trigger any event. Clients can receive these events in real time and update their front-end application accordingly.

User

Get Metadata for All Users

Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All UUID Metadata you can use the following method(s) in the Go SDK:

pn.GetAllUUIDMetadata().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataInclude
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values: pubnub.PNUUIDMetadataIncludeCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Count
Type: bool
Request Count to be included in paginated response. By default, Count is omitted.
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities).

Basic Usage

Reference code

This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

package main

import (
"fmt"
pubnub "github.com/pubnub/go/v7"
)

func main() {
config := pubnub.NewConfigWithUserId("myUniqueUserId")
config.SubscribeKey = "demo"
config.PublishKey = "demo"
pn := pubnub.NewPubNub(config)

incl := []pubnub.PNUUIDMetadataInclude{pubnub.PNUUIDMetadataIncludeCustom}

show all 40 lines

Response

The GetAllUUIDMetadata() operation returns a PNGetAllChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNUUID
Details of type PNUUID are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Get User Metadata

Returns metadata for the specified UUID, optionally including the custom data object for each.

Method(s)

To Get UUID Metadata you can use the following method(s) in the Go SDK:

pn.PNUUIDMetadataInclude().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
ID(string).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataIncludeCustom
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNUUIDMetadataIncludeCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Basic Usage

id := "testuuid"
incl := []pubnub.PNUUIDMetadataInclude{
pubnub.PNUUIDMetadataIncludeCustom,
}
res, status, err := pn.GetUUIDMetadata().
UUID(id).
Include(incl).
Execute()
fmt.Println(res, status, err)

Response

The GetUUIDMetadata() operation returns a PNGetUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
PNUUID
Details of type PNUUID are here

Set User Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a UUID in the database, optionally including the custom data object for each.

Method(s)

To Set UUID Metadata you can use the following method(s) in the Go SDK:

pn.SetUUIDMetadata().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
ID(id).
Name(string).
ExternalID(string).
ProfileURL(string).
Email(string).
Custom(map[string]interface{}).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataInclude
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values: pubnub.PNUUIDMetadataIncludeCustom
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Name *
Type: string
Display name for the user.
ExternalID
Type: string
User's identifier in an external system
ProfileURL
Type: string
The URL of the user's profile picture
Email
Type: string
The user's email address.
Custom
Type: map[string]interface
JSON object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Basic Usage

id := "testuuid"
name := "name"
extid := "extid"
purl := "profileurl"
email := "email"

custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"

incl := []pubnub.PNUUIDMetadataInclude{
pubnub.PNUUIDMetadataIncludeCustom,
}

res, status, err := pn.SetUUIDMetadata()
show all 24 lines

Response

The SetUUIDMetadata() operation returns a PNSetUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
PNUUID
Details of type PNUUID are here

PNUUID

Property NameTypeDescription
ID
string
Unique user identifier. If not supplied then current user's uuid is used.
Name
string
Display name for the user.
ExternalID
string
User's identifier in an external system
ProfileURL
string
The URL of the user's profile picture
Email
string
The user's email address.
Custom
map[string]interface
JSON object of key-value pairs with supported data types.
Updated
string
Last updated date.
ETag
string
The ETag.

Remove User Metadata

Removes the metadata from a specified UUID.

Method(s)

To Remove UUID Metadata you can use the following method(s) in the Go SDK:

pn.RemoveUUIDMetadata().
ID(string).
Execute()
* required
ParameterDescription
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Basic Usage

id := "testuuid"
res, status, err := pn.RemoveUUIDMetadata()
.UUID(id)
.Execute()
fmt.Println(res, status, err)

Response

The RemoveUUIDMetadata() operation returns a PNRemoveUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
interface
Returns an empty interface.

Channel

Get Metadata for All Channels

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All Channel Metadata you can use the following method(s) in the Go SDK:

pn.GetAllChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Count
Type: bool
Request Count to be included in paginated response. By default, Count is omitted.
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities).

Basic Usage

incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.GetAllChannelMetadata()
.Include(incl)
.Sort(sort)
.Limit(100)
.Count(true)
.Execute()
fmt.Println(res, status, err)

Response

The GetAllChannelMetadata() operation returns a PNGetAllChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNChannel
Details of type PNChannel are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Get Channel Metadata

Returns metadata for the specified Channel, optionally including the custom data object for each.

Method(s)

To Get Channel Metadata you can use the following method(s) in the Go SDK:

pn.GetChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
ID(string).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Basic Usage

id := "testchannel"
incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.GetChannelMetadata()
.Include(incl)
.Channel(id)
.Execute()
fmt.Println(res, status, err)

Response

The GetChannelMetadata() operation returns a PNGetChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
PNChannel
Details of type PNChannel are here

Set Channel Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a Channel in the database, optionally including the custom data object for each.

Method(s)

To Set Channel Metadata you can use the following method(s) in the Go SDK:

pn.SetChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
ID(string).
Name(string).
Description(string).
Custom(map[string]interface{}).
Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Name *
Type: string
Name of a channel.
Description
Type: string
Description of a channel.
Custom
Type: map[string]interface
Map of string and interface with supported data types. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Basic Usage

id := "testchannel"
name := "name"
desc := "desc"
custom := make(map[string]interface{}) custom["a"] = "b" custom["c"] = "d"
incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.SetChannelMetadata()
.Include(incl)
.Channel(id)
.Name(name)
.Description(desc)
.Custom(custom)
.Execute()

Response

The SetChannelMetadata() operation returns a PNSetChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
PNChannel
Details of type PNChannel are here

PNChannel

Property NameTypeDescription
ID
string
Unique user identifier. If not supplied then current user's uuid is used.
Name
string
Display name for the user.
Description
string
Description of a channel.
Custom
map[string]interface
Map of string and interface with supported data types. Values must be scalar only; arrays or objects are not supported.
Updated
string
Last updated date.
ETag
string
The ETag.

Other Examples

Iteratively update existing metadata
package main

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/pubnub/go/v7"
)

func main() {
config := pubnub.NewConfig()
config.SubscribeKey = "demo"
config.PublishKey = "demo"
show all 119 lines

Remove Channel Metadata

Removes the metadata from a specified channel.

Method(s)

To Remove Channel Metadata you can use the following method(s) in the Go SDK:

pn.RemoveChannelMetadata().
ID(string).
Execute()
* required
ParameterDescription
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Basic Usage

id := "testchannel"
res, status, err := pn.RemoveChannelMetadata().Channel(id).Execute()

Response

The RemoveChannelMetadata() operation returns a PNRemoveChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data
interface
Returns an empty interface.

Channel Memberships

Get Channel Memberships

The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.

Method(s)

To Get Memberships you can use the following method(s) in the Go SDK:

pn.GetMemberships().
UUID(string).
Include([]pubnub.PNMembershipsInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
* required
ParameterDescription
UUID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Number of objects to return in response. Default is 100, which is also the maximum value.
Count
Type: bool
Request Count to be included in paginated response. By default, Count is omitted.
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities).

Basic Usage

inclMemberships := []pubnub.PNMembershipsInclude{
pubnub.PNMembershipsIncludeCustom,
pubnub.PNMembershipsIncludeChannel,
pubnub.PNMembershipsIncludeChannelCustom,
}

res, status, err := pn.GetMemberships()
.UUID("testuuid")
.Include(inclMemberships)
.Limit(100)
.Count(true)
.Execute()

Response

The GetMemberships() operation returns a PNGetMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNMemberships
Details of type PNMemberships are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

PNMemberships

Property NameTypeDescription
ID
string
Unique user identifier. If not supplied then current user's uuid is used.
Channel
PNChannel
Details of type PNChannel are here
Custom
map[string]interface
Map of string and interface with supported data types.
Updated
string
Last updated date.
ETag
string
The ETag.

Set Channel Memberships

Set channel memberships for a UUID.

Method(s)

To Set Memberships you can use the following method(s) in the Go SDK:

pn.SetMemberships().
UUID(string).
Set([]pubnub.PNMembershipsSet).
Include([]pubnub.PNMembershipsInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
UUID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Set
Type: pubnub.PNMembershipsSet
Struct of type pubnub.PNMembershipsSet to be added for the specified UUID. In PNMembershipsSet you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
API limits

To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.

Basic Usage

inclMemberships := []pubnub.PNMembershipsInclude{
pubnub.PNMembershipsIncludeCustom,
pubnub.PNMembershipsIncludeChannel,
pubnub.PNMembershipsIncludeChannelCustom,
}

custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"
channel := pubnub.PNMembershipsChannel{
ID: "testchannel",
}

inMem := pubnub.PNMembershipsSet{
ID: channel,
show all 29 lines

Response

The SetMemberships() operation returns a PNSetMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNMemberships
Details of type PNMemberships are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Remove Channel Memberships

Remove channel memberships for a UUID.

Method(s)

To Remove Memberships you can use the following method(s) in the Go SDK:

pn.RemoveMemberships().
UUID(string).
Remove([]pubnub.PNMembershipsRemove).
Include([]pubnub.PNMembershipsInclude).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
UUID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Remove
Type: pubnub.PNMembershipsRemove
Struct of type pubnub.PNMembershipsRemove to be added for the specified UUID. In PNMembershipsRemove you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.

Basic Usage

inclMemberships := []pubnub.PNMembershipsInclude{
pubnub.PNMembershipsIncludeCustom,
pubnub.PNMembershipsIncludeChannel,
pubnub.PNMembershipsIncludeChannelCustom,
}
channel := pubnub.PNMembershipsChannel{
ID: "testchannel",
}
reMem := pubnub.PNMembershipsRemove{
ID: channel,
}
reArrMem := []pubnub.PNMembershipsRemove{
reMem,
}
res, status, err := pn.RemoveMemberships()
show all 22 lines

Response

The RemoveMemberships() operation returns a PNRemoveMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNMemberships
Details of type PNMemberships are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Manage Channel Memberships

Manage the specified UUID's memberships. You can Add, Remove, and Update a UUID's memberships.

Method(s)

To Manage Memberships you can use the following method(s) in the Go SDK:

pn.ManageMemberships().
UUID(string).
Set([]pubnub.PNMembershipsSet).
Remove([]pubnub.PNMembershipsRemove).
Include([]pubnub.PNMembershipsInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
UUID
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Set
Type: pubnub.PNMembershipsSet
Struct of type pubnub.PNMembershipsSet to be added for the specified UUID. In PNMembershipsSet you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Remove
Type: pubnub.PNMembershipsRemove
Struct of type pubnub.PNMembershipsRemove to be added for the specified UUID. In PNMembershipsRemove you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type )
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.

Basic Usage

inclMemberships := []pubnub.PNMembershipsInclude{
pubnub.PNMembershipsIncludeCustom,
pubnub.PNMembershipsIncludeChannel,
pubnub.PNMembershipsIncludeChannelCustom,
}

custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"
channel := pubnub.PNMembershipsChannel{
ID: "testchannel",
}

inMem := pubnub.PNMembershipsSet{
ID: channel,
show all 30 lines

Response

The ManageMemberships() operation returns a PNManageMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNMemberships
Details of type PNMemberships are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Channel Members

Get Channel Members

The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.

Method(s)

To Get Channel Members you can use the following method(s) in the Go SDK:

pn.GetChannelMembers().
Channel(string).
Include(PNChannelMembersInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
* required
ParameterDescription
Channel *
Type: string
Channel name.
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
Filter
Type: string
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities).

Basic Usage

inclSm := []pubnub.PNChannelMembersInclude{
pubnub.PNChannelMembersIncludeCustom,
pubnub.PNChannelMembersIncludeUUID,
pubnub.PNChannelMembersIncludeUUIDCustom,
}

res, status, err := pn.GetChannelMembers()
.Channel("testchannel")
.Include(inclSm)
.Limit(100)
.Count(true)
.Execute()
fmt.Println(res, status, err)

Response

The GetChannelMembers() operation returns a PNGetChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNChannelMembers
Details of type PNChannelMembers are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

PNChannelMembers

Property NameTypeDescription
ID
string
Unique user identifier. If not supplied then current user's uuid is used.
UUID
PNUUID
Details of type PNUUID are here
Custom
map[string]interface
Map of string and interface with supported data types.
Updated
string
Last updated date.
ETag
string
The ETag.

Set Channel Members

This method sets members in a channel.

Method(s)

To Set Channel Members you can use the following method(s) in the Go SDK:

pn.SetChannelMembers().
Channel(string).
Set([]pubnub.PNChannelMembersSet).
Include([]pubnub.PNChannelMembersInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
Channel *
Type: string
Channel name.
Set
Type: pubnub.PNChannelMembersSet
Struct of type pubnub.PNChannelMembersSet to be added for the specified space. In PNChannelMembersSet you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
API limits

To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.

Basic Usage

inclSm := []pubnub.PNChannelMembersInclude{
pubnub.PNChannelMembersIncludeCustom,
pubnub.PNChannelMembersIncludeUUID,
pubnub.PNChannelMembersIncludeUUIDCustom,
}
custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"
uuid := pubnub.PNChannelMembersUUID{
ID: "testuuid",
}
inputUUID := pubnub.PNChannelMembersSet{
UUID: uuid,
Custom: custom,
}
show all 28 lines

Response

The SetChannelMembers() operation returns a PNSetChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNChannelMembers
Details of type PNChannelMembers are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Remove Channel Members

Remove members from a Channel.

Method(s)

To Remove Channel Members you can use the following method(s) in the Go SDK:

pn.RemoveChannelMembers().
Channel(string).
Remove([]pubnub.PNChannelMembersRemove{}).
Include([]pubnub.PNChannelMembersInclude).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Name of channel from which members should be fetched.
uuids *
Type: Array
Default:
n/a
List of UUIDs for which metadata associated with each of them in context of channel should be set. Each entry is dictionary with UUID and optional custom fields. custom should be dictionary with simple objects: String and Integer.
sort
Type: Array
Default:
n/a
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
include
Type: Object
Default:
{ count: true }
Additional information which should be included in response. Available options:
  • count- include how many UUID has been associated with metadata.
  • custom - include field with additional information from metadata which has been used during UUID metadata set requests.
filter
Type: String
Default:
n/a
Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here
start
Type: String
Default:
n/a
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
end
Type: String
Default:
n/a
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the start parameter is supplied.
limit
Type: Integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
http_sync
Type: Boolean
Default:
false
Method will be executed asynchronously and will return future, to get its value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope). For sync methods Envelope object will be returned.
callback
Type: Lambda accepting one parameter
Default:
n/a
Callback that will be called for each envelope. For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Basic Usage

inclSm := []pubnub.PNChannelMembersInclude{
pubnub.PNChannelMembersIncludeCustom,
pubnub.PNChannelMembersIncludeUUID,
pubnub.PNChannelMembersIncludeUUIDCustom,
}
uuid := pubnub.PNChannelMembersUUID{
ID: "testuuid",
}
re := pubnub.PNChannelMembersRemove{
UUID: uuid,
}

reArr := []pubnub.PNChannelMembersRemove{
re,
}
show all 24 lines

Response

The RemoveChannelMembers() operation returns a PNRemoveChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNChannelMembers
Details of type PNChannelMembers are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.

Manage Channel Members

The method Set and Remove channel memberships for a user.

Method(s)

To Manage Channel Members you can use the following method(s) in the Go SDK:

pn.ManageChannelMembers().
Channel(string).
Set([]pubnub.PNChannelMembersSet).
Remove([]pubnub.PNChannelMembersRemove{}).
Include([]pubnub.PNChannelMembersInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Execute()
* required
ParameterDescription
Channel *
Type: string
Channel Name.
Set
Type: pubnub.PNChannelMembersSet
Struct of type pubnub.PNChannelMembersSet to be added for the specified space. In PNChannelMembersSet you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type ) and a Custom map.
Remove
Type: pubnub.PNChannelMembersRemove
Struct of type pubnub.PNChannelMembersRemove to be removed for the specified space. In PNChannelMembersRemove you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type )
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Request TotalCount to be included in paginated response. Default false
Start
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
End
Type: string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Start parameter is supplied.
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom

Basic Usage

inclSm := []pubnub.PNChannelMembersInclude{
pubnub.PNChannelMembersIncludeCustom,
pubnub.PNChannelMembersIncludeUUID,
pubnub.PNChannelMembersIncludeUUIDCustom,
}
custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"
uuid := pubnub.PNChannelMembersUUID{
ID: "testuuid",
}
inputUUID := pubnub.PNChannelMembersSet{
UUID: uuid,
Custom: custom,
}
show all 29 lines

Response

The ManageChannelMembers() operation returns a PNManageMembersResponse which contains the following parameters:

Property NameTypeDescription
Data
[]PNChannelMembers
Details of type PNChannelMembers are here
TotalCount
int
Total count of objects without pagination.
Next
string
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Prev
string
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied.
Last updated on