Categorygithub.com/webpubsub/sdk-go/v7
modulepackage
7.0.0-20220628080633-bf57de9e8a46
Repository: https://github.com/webpubsub/sdk-go.git
Documentation: pkg.go.dev

# README

WebPubSub Go SDK

GoDoc Build Status codecov.io Go Report Card

This is the official WebPubSub Go SDK repository.

WebPubSub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let WebPubSub handle sending and receiving data across the world in less than 100ms.

Requirements

  • Go (1.9+)

Get keys

You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.

Configure WebPubSub

  1. Integrate WebPubSub into your project using the go command:

    go get github.com/webpubsub/sdk-go
    

    If you encounter dependency issues, use the dep ensure command to resolve them.

  2. Create a new file and add the following code:

    func main() {
        config := webpubsub.NewConfig()
        config.SubscribeKey = "mySubscribeKey"
        config.PublishKey = "myPublishKey"
        config.UUID = "myUniqueUUID"
    
        pn := webpubsub.NewWebPubSub(config)
    }
    

Add event listeners

listener := webpubsub.NewListener()
doneConnect := make(chan bool)
donePublish := make(chan bool)

msg := map[string]interface{}{
    "msg": "Hello world",
}
go func() {
    for {
        select {
        case status := <-listener.Status:
            switch status.Category {
            case webpubsub.WPSDisconnectedCategory:
                // This event happens when radio / connectivity is lost
            case webpubsub.WPSConnectedCategory:
                // Connect event. You can do stuff like publish, and know you'll get it.
                // Or just use the connected event to confirm you are subscribed for
                // UI / internal notifications, etc
                doneConnect <- true
            case webpubsub.WPSReconnectedCategory:
                // Happens as part of our regular operation. This event happens when
                // radio / connectivity is lost, then regained.
            }
        case message := <-listener.Message:
            // Handle new message stored in message.message
            if message.Channel != "" {
                // Message has been received on channel group stored in
                // message.Channel
            } else {
                // Message has been received on channel stored in
                // message.Subscription
            }
            if msg, ok := message.Message.(map[string]interface{}); ok {
                fmt.Println(msg["msg"])
            }
            /*
                log the following items with your favorite logger
                    - message.Message
                    - message.Subscription
                    - message.Timetoken
            */

            donePublish <- true
        case <-listener.Presence:
            // handle presence
        }
    }
}()

pn.AddListener(listener)

Publish and subscribe

In this code, publishing a message is triggered when the subscribe call is finished successfully. The Publish() method uses the msg variable that is used in the following code.

msg := map[string]interface{}{
        "msg": "Hello world!"
}

pn.Subscribe().
    Channels([]string{"hello_world"}).
    Execute()

<-doneConnect

response, status, err := pn.Publish().
    Channel("hello_world").Message(msg).Execute()

if err != nil {
     // Request processing failed.
     // Handle message publish error
}

Documentation

API reference for Go

Support

If you need help or have a general question, contact [email protected].

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

EnumArrayToStringArray converts a string enum to an array.
No description provided by the author
GetPermissions decodes the CBORToken.
NewConfig initiates the config with default values.
NewDemoConfig initiates the config with demo keys, for tests only.
NewHTTP1Client creates a new HTTP 1 client with a new transport initialized with connect and read timeout.
NewHTTP2Client creates a new HTTP 2 client with a new transport initialized with connect and read timeout.
NewListener initates the listener to facilitate the event handling.
NewWebPubSub instantiates a WebPubSub instance with default values.
NewWebPubSubDemo returns an instance with demo keys.
ParseFileInfo is a function extract file info and add to the struct WPSFileMessageAndDetails.
ParseGrantResources parses the token for permissions and adds them along the other values to the GrantResourcesWithPermissions struct.
No description provided by the author
SetArrayTypeQueryParam appends to the query string the key val pair.
SetPushEnvironment appends the push environment to the query string.
SetPushTopic appends the topic to the query string.
SetQueryParam appends the query params map to the query string.
SetQueryParamAsCommaSepString appends to the query string the comma separated string.

# Constants

MaxSequence for publish messages.
StrChannelsTimetoken shows Missing Channels Timetoken message.
StrChannelsTimetokenLength shows Length of Channels Timetoken message.
StrInvalidTTL shows Invalid TTL message.
StrMissingChannel shows Channel message.
StrMissingChannelGroup shows Channel Group message.
StrMissingDeviceID shows Missing Device ID message.
StrMissingFileID shows `Missing File ID` message.
StrMissingFileName shows `Missing File Name` message.
StrMissingMessage shows Missing Message message.
StrMissingPubKey shows Missing Publish Key message.
StrMissingPushTitle shows `Push title missing` message.
StrMissingPushTopic shows Missing Push Topic message.
StrMissingPushType shows Missing Push Type message.
StrMissingSecretKey shows Missing Secret Key message.
StrMissingSubKey shows Missing Subscribe Key message.
StrMissingToken shows `Missing PAMv3 token` message.
StrMissingUUID shows Missing UUID message.
Version :the version of the SDK.
WPSAccessDeniedCategory as the StatusCategory means that PAM is enabled and the channel is not granted R/W access.
WPSAccessManagerGrant is the enum used for the Access Manager Grant operation.
WPSAccessManagerGrantToken is the enum used for Grant v3 requests.
WPSAccessManagerRevoke is the enum used for the Access Manager Revoke operation.
WPSAccessManagerRevokeToken is the enum used for Grant Token remove requests.
WPSAcknowledgmentCategory as the StatusCategory is the Acknowledgement of an operation (like Unsubscribe).
WPSAddChannelsToChannelGroupOperation is the enum used for the Add Channels to Channel Group operation.
WPSAddMessageActionsOperation is the enum used for Message Actions Add requests.
WPSAddPushNotificationsOnChannelsOperation is the enum used for the Add Channels to Push Notifications operation.
WPSBadRequestCategory as the StatusCategory means the request was malformed.
WPSCancelledCategory as the StatusCategory means the context was cancelled.
WPSChannelMembersIncludeCustom is the enum equivalent to the value `custom` available Members include types.
WPSChannelMembersIncludeUUID is the enum equivalent to the value `uuid` available Members include types.
WPSChannelMembersIncludeUUIDCustom is the enum equivalent to the value `uuid.custom` available Members include types.
WPSChannelMetadataIncludeCustom is the enum equivalent to the value `custom` available Channel include types.
WPSChannels for channels.
WPSChannelsForGroupOperation is the enum used for the List Channels of Channel Group operation.
WPSConnectedCategory as the StatusCategory means the channel is subscribed to receive messages.
WPSCreate Create Perms.
WPSCreateEnabled Create Enabled.
WPSCreateSpaceOperation is the enum used to create space in the Object API.
WPSCreateUserOperation is the enum used to create users in the Object API.
WPSDelete Delete Perms.
WPSDeleteEnabled Delete Enabled.
WPSDeleteFileOperation is the enum used for DeleteFile requests.
WPSDeleteMessagesOperation is the enum used for the Delete Messages from History operation.
WPSDeleteSpaceOperation is the enum used to delete space in the Object API.
WPSDeleteUserOperation is the enum used to delete users in the Object API.
WPSDisconnectedCategory as the StatusCategory means a disconnection occurred due to network issues.
WPSDownloadFileOperation is the enum used for DownloadFile requests.
WPSExponentialPolicycy is to be used when selecting the Exponential Reconnection Policy ReconnectionPolicy is set in the config.
WPSFetchMessagesOperation is the enum used for the Fetch operation.
WPSFireOperation is the enum used for the Fire operation.
WPSGet Get Perms.
WPSGetAllChannelMetadataOperation is the enum used to Get All Channel Metadata in the Object API.
WPSGetAllUUIDMetadataOperation is the enum used to Get All UUID Metadata in the Object API.
WPSGetChannelMembersOperation is the enum used to get members in the Object API.
WPSGetChannelMetadataOperation is the enum used to Get Channel Metadata in the Object API.
WPSGetEnabled Get Enabled.
WPSGetFileURLOperation is the enum used for GetFileURL requests.
WPSGetMembershipsOperation is the enum used to get memberships in the Object API.
WPSGetMessageActionsOperation is the enum used for Message Actions Get requests.
WPSGetSpaceOperation is the enum used to get space in the Object API.
WPSGetSpacesOperation is the enum used to get spaces in the Object API.
WPSGetStateOperation is the enum used for the Get State operation.
WPSGetUserOperation is the enum used to get user in the Object API.
WPSGetUsersOperation is the enum used to get users in the Object API.
WPSGetUUIDMetadataOperation is the enum used to Get UUID Metadata in the Object API.
WPSGroups for groups.
WPSHeartBeatOperation is the enum used for the Heartbeat operation.
WPSHereNowOperation is the enum used for the Here Now operation.
WPSHistoryOperation is the enum used for the History operation.
WPSHistoryWithActionsOperation is the enum used for History with Actions requests.
WPSJoin Join Perms.
WPSJoinEnabled Join Enabled.
WPSLinearPolicy is to be used when selecting the Linear Reconnection Policy ReconnectionPolicy is set in the config.
WPSListFilesOperation is the enum used for ListFiles requests.
WPSLoopStopCategory as the StatusCategory means the subscribe loop was stopped.
WPSManage Manage Perms.
WPSManageEnabled Manage Enabled.
WPSManageMembershipsOperation is the enum used to manage memberships in the Object API.
WPSManageMembersOperation is the enum used to manage members in the Object API.
WPSMembershipsIncludeChannel is the enum equivalent to the value `channel` available Memberships include types.
WPSMembershipsIncludeChannelCustom is the enum equivalent to the value `channel.custom` available Memberships include types.
WPSMembershipsIncludeCustom is the enum equivalent to the value `custom` available Memberships include types.
WPSMessageActionsAdded is the enum when the event of type `added` occurs.
WPSMessageActionsRemoved is the enum when the event of type `removed` occurs.
WPSMessageCountsOperation is the enum used for History with messages operation.
WPSMessageTypeFile is to identify Files the Subscribe response.
WPSMessageTypeMessageActions is to identify Actions the Subscribe response.
WPSMessageTypeObjects is to identify Objects the Subscribe response.
WPSMessageTypeSignal is to identify Signal the Subscribe response.
WPSNonePolicy is to be used when selecting the no Reconnection Policy ReconnectionPolicy is set in the config.
WPSNoStubMatchedCategory as the StatusCategory means an unknown status category event occurred.
WPSObjectsChannelEvent is the enum when the event of type `channel` occurs.
WPSObjectsEventRemove is the enum when the event `delete` occurs.
WPSObjectsEventSet is the enum when the event `set` occurs.
WPSObjectsMembershipEvent is the enum when the event of type `membership` occurs.
WPSObjectsNoneEvent is used for error handling.
WPSObjectsUUIDEvent is the enum when the event of type `uuid` occurs.
WPSPublishFileMessageOperation is the enum used for PublishFileMessage requests.
WPSPublishOperation is the enum used for the Publish operation.
WPSPushEnvironmentDevelopment for development.
WPSPushEnvironmentProduction for production.
WPSPushNotificationsEnabledChannelsOperation is the enum used for the List Channels with Push Notifications enabled operation.
WPSPushTypeAPNS is used as an enum to for selecting `APNS` as the WPSPushType.
WPSPushTypeAPNS2 is used as an enum to for selecting `APNS2` as the WPSPushType.
WPSPushTypeGCM is used as an enum to for selecting `GCM` as the WPSPushType.
WPSPushTypeMPNS is used as an enum to for selecting `MPNS` as the WPSPushType.
WPSPushTypeNone is used as an enum to for selecting `none` as the WPSPushType.
WPSRead Read Perms.
WPSReadEnabled Read Enabled.
WPSReconnectedCategory as the StatusCategory means that the network was reconnected (after a disconnection).
WPSReconnectionAttemptsExhausted as the StatusCategory means that the reconnection attempts to reconnect to the network were exhausted.
WPSRemoveAllPushNotificationsOperation is the enum used for the Remove All Channels from Push Notifications operation.
WPSRemoveChannelFromChannelGroupOperation is the enum used for the Remove Channels from Channel Group operation.
WPSRemoveChannelMembersOperation is the enum used to Remove Members in the Object API.
WPSRemoveChannelMetadataOperation is the enum used to Remove Channel Metadata in the Object API.
WPSRemoveGroupOperation is the enum used for the Remove Channel Group operation.
WPSRemoveMembershipsOperation is the enum used to Remove Memberships in the Object API.
WPSRemoveMessageActionsOperation is the enum used for Message Actions Remove requests.
WPSRemovePushNotificationsFromChannelsOperation is the enum used for the Remove Channels from Push Notifications operation.
WPSRemoveUUIDMetadataOperation is the enum used to Remove UUID Metadata in the Object API.
WPSRequestMessageCountExceededCategory is fired when the MessageQueueOverflowCount limit is exceeded by the number of messages received in a single subscribe request.
WPSSendFileOperation is the enum used for SendFile requests.
WPSSendFileToS3Operation is the enum used for v requests.
WPSSetChannelMembersOperation is the enum used to Set Members in the Object API.
WPSSetChannelMetadataOperation is the enum used to Set Channel Metadata in the Object API.
WPSSetMembershipsOperation is the enum used to Set Memberships in the Object API.
WPSSetStateOperation is the enum used for the Set State operation.
WPSSetUUIDMetadataOperation is the enum used to Set UUID Metadata in the Object API.
WPSSignalOperation is the enum used for Signal opertaion.
WPSSubscribeOperation is the enum used for the Subcribe operation.
WPSTimeOperation is the enum used for the Time operation.
WPSTimeoutCategory as the StatusCategory means the request timeout has reached.
WPSUnknownCategory as the StatusCategory means an unknown status category event occurred.
WPSUnsubscribeOperation is the enum used for the Unsubcribe operation.
WPSUpdate Update Perms.
WPSUpdateEnabled Update Enabled.
WPSUpdateSpaceOperation is the enum used to update space in the Object API.
WPSUpdateUserOperation is the enum used to update users in the Object API.
WPSUUIDMetadataIncludeCustom is the enum equivalent to the value `custom` available UUID include types.
WPSUsers for users.
WPSWhereNowOperation is the enum used for the Where Now operation.
WPSWrite Write Perms.
WPSWriteEnabled Write Enabled.

# Structs

AddChannelToChannelGroupResponse is the struct returned when the Execute function of AddChannelToChannelGroup is called.
AddPushNotificationsOnChannelsResponse is response structure for AddPushNotificationsOnChannelsBuilder.
AllChannelGroupResponse is the struct returned when the Execute function of List All Channel Groups is called.
ChannelPermissions contains all the acceptable perms for channels.
ChannelPermissionsWithToken is used for channels resource type permissions.
Config instance is storage for user-provided information which describe further WebPubSub client behaviour.
DeleteChannelGroupResponse is response structure for Delete Channel Group function.
FetchResponse is the response to Fetch request.
FetchResponseItem contains the message and the associated timetoken.
GetStateResponse is the struct returned when the Execute function of GetState is called.
GrantResources is the struct used to decode the server response.
GrantResourcesWithPermissions is used as a common struct to store all resource type permissions.
GrantResponse is the struct returned when the Execute function of Grant is called.
GroupPermissions contains all the acceptable perms for groups.
GroupPermissionsWithToken is used for groups resource type permissions.
HeartbeatManager is a struct that assists in running of the heartbeat.
HereNowChannelData is the struct containing the occupancy details of the channels.
HereNowOccupantsData is the struct containing the state and UUID of the occupants in the channel.
HereNowResponse is the struct returned when the Execute function of HereNow is called.
HistoryDeleteResponse is the struct returned when Delete Messages is called.
HistoryResponse is used to store the response from the History request.
HistoryResponseItem is used to store the Message and the associated timetoken from the History request.
JobQItem is the type to store the request, client and its resposne.
JobQResponse is the type to store the resposne and error of the requests in the queue.
LatencyEntry is the struct to store the timestamp and latency values.
Listener type has all the `types` of response events.
ListenerManager is used in the internal handling of listeners.
ListPushProvisionsRequestResponse is the struct returned when the Execute function of ListPushProvisions is called.
MessageAction struct is used to create a Message Action.
MessageCountsResponse is the response to MessageCounts request.
Operations is the struct to store the latency values of different operations.
PermissionsBody is the struct used to decode the server response.
PublishFileMessageResponse is the response to PublishFileMessage request.
PublishResponse is the response after the execution on Publish and Fire operations.
ReconnectionManager is used to store the properties required in running the Reconnection Manager.
RemoveAllPushChannelsForDeviceResponse is the struct returned when the Execute function of RemoveAllPushNotifications is called.
RemoveChannelFromChannelGroupResponse is the struct returned when the Execute function of RemoveChannelFromChannelGroup is called.
RemoveChannelsFromPushResponse is the struct returned when the Execute function of RemovePushNotificationsFromChannels is called.
RequestWorkers is the type to store the workers info.
ResponseInfo is used to store the properties in the response of an request.
SetChannelMetadataBody is the input to update space.
SetStateResponse is the response returned when the Execute function of SetState is called.
SetUUIDMetadataBody is the input to update user.
SignalResponse is the response to Signal request.
StateManager is used to store the subscriptions types.
StateOperation is the types to store state op params.
StatusResponse is used to store the usable properties in the response of an request.
SubscribeOperation is the type to store the subscribe op params.
SubscriptionItem is used to store the subscription item's properties.
SubscriptionManager Events: - ConnectedCategory - after connection established - DisconnectedCategory - after subscription loop stops for any reason (no channels left or error happened) Unsubscribe When you unsubscribe from channel or channel group the following events happens: - LoopStopCategory - immediately when no more channels or channel groups left to subscribe - WPSUnsubscribeOperation - after leave request was fulfilled and server is notified about unsubscibed items Announcement: Status, Message and Presence announcement happens in a distinct goroutine.
TelemetryManager is the struct to store the Telemetry details.
TimeResponse is the response when Time call is executed.
TokenManager struct is used to for token manager operations.
UnsubscribeOperation is the types to store unsubscribe op params.
No description provided by the author
WebPubSub No server connection will be established when you create a new WebPubSub object.
WhereNowResponse is the response of the WhereNow request.
Worker is the type to store the worker info.
WPSAccessManagerKeyData is the struct containing the access details of the channel groups.
WPSAddMessageActionsResponse is the Add Message Actions API Response.
WPSAPNS2Data is the struct used for the APNS2 paylod.
WPSAPNSData is the struct used for the APNS paylod.
WPSAPSData is the helper struct used for the APNS paylod.
WPSChannel is the Objects API space struct.
WPSChannelEvent is the Response for a Space Event.
WPSChannelMembers is the Objects API Members struct.
WPSChannelMembersRemove is the Objects API Members struct used to remove members.
WPSChannelMembersRemoveChangeset is the Objects API input to add, remove or update membership.
WPSChannelMembersSet is the Objects API Members input struct used to add members.
WPSChannelMembersSetChangeset is the Objects API input to add, remove or update membership.
WPSChannelMembersUUID is the Objects API Members input struct used to add members.
WPSDeleteFileResponse is the File Upload API Response for Delete file operation.
WPSDownloadFileResponse is the File Upload API Response for Get Spaces.
WPSFCMData is the struct used for the FCM paylod.
WPSFCMDataFields is the helper struct used for the FCM paylod.
WPSFileData is used in the responses to show File ID.
WPSFileDetails is used in the responses to show File Info.
WPSFileInfo is the File Upload API struct returned on for each file.
WPSFileInfoForPublish is the part of the message struct used in Publish File.
WPSFileMessageAndDetails is used to store the file message and file info.
WPSFilesEvent is the Response for a Files Event.
WPSFileUploadRequest is used to store the info related to file upload to S3.
WPSFormField is part of the struct used in file upload to S3.
WPSGetAllChannelMetadataResponse is the Objects API Response for Get Spaces.
WPSGetAllUUIDMetadataResponse is the Objects API Response for Get Users.
WPSGetChannelMembersResponse is the Objects API Response for Get Members.
WPSGetChannelMetadataResponse is the Objects API Response for Get Space.
WPSGetFileURLResponse is the File Upload API Response for Get Spaces.
WPSGetMembershipsResponse is the Objects API Response for Get Memberships.
WPSGetMessageActionsMore is the struct used when the WPSGetMessageActionsResponse has more link.
WPSGetMessageActionsResponse is the GetMessageActions API Response.
WPSGetUUIDMetadataResponse is the Objects API Response for Get User.
WPSGrantTokenData is the struct used to decode the server response.
WPSGrantTokenDecoded is the struct used to decode the server response.
WPSGrantTokenResponse is the struct returned when the Execute function of Grant Token is called.
WPSHistoryMessageActionsTypeMap is the struct used in the Fetch request that includes Message Actions.
WPSHistoryMessageActionTypeVal is the struct used in the Fetch request that includes Message Actions.
WPSListFilesResponse is the File Upload API Response for Get Spaces.
WPSManageChannelMembersBody is the Objects API input to add, remove or update members.
WPSManageMembershipsBody is the Objects API input to add, remove or update membership.
WPSManageMembershipsResponse is the Objects API Response for ManageMemberships.
WPSManageMembersResponse is the Objects API Response for ManageMembers.
WPSMembersAddChangeSet is the Objects API input to add, remove or update members.
WPSMembershipEvent is the Response for a Membership Event.
WPSMemberships is the Objects API Memberships struct.
WPSMembershipsChannel is the Objects API Memberships input struct used to add members.
WPSMembershipsRemove is the Objects API Memberships struct used to remove members.
WPSMembershipsRemoveChangeSet is the Objects API input to add, remove or update members.
WPSMembershipsSet is the Objects API Memberships input struct used to add members.
WPSMessage is the Message Response for Subscribe.
WPSMessageActionsEvent is the Response for a Message Actions Event.
WPSMessageActionsResponse Message Actions response.
WPSMPNSData is the struct used for the MPNS paylod.
WPSObjectsResponse is the Objects API collective Response struct of all methods.
WPSPAMEntityData is the struct containing the access details of the channels.
WPSPresence is the Message Response for Presence.
WPSPublishFileMessage is the message struct used in Publish File.
WPSPublishMessage is the part of the message struct used in Publish File.
WPSPushTarget is the helper struct used for the APNS2 paylod.
WPSRemoveChannelMembersResponse is the Objects API Response for RemoveChannelMembers.
WPSRemoveChannelMetadataResponse is the Objects API Response for delete space.
WPSRemoveMembershipsResponse is the Objects API Response for RemoveMemberships.
WPSRemoveMessageActionsResponse is the Objects API Response for create space.
WPSRemoveUUIDMetadataResponse is the Objects API Response for delete user.
WPSRevokeTokenResponse is the struct returned when the Execute function of Grant Token is called.
WPSSendFileBody is used to create the body of the request.
WPSSendFileResponse is the type used to store the response info of Send File.
WPSSendFileResponseForS3 is the File Upload API Response for SendFile.
WPSSendFileToS3Response is the File Upload API Response for Get Spaces.
WPSSetChannelMembersResponse is the Objects API Response for SetChannelMembers.
WPSSetChannelMetadataResponse is the Objects API Response for Update Space.
WPSSetMembershipsResponse is the Objects API Response for SetMemberships.
WPSSetUUIDMetadataResponse is the Objects API Response for Update user.
WPSStatus is the status struct.
No description provided by the author
No description provided by the author
WPSUUID is the Objects API user struct.
WPSUUIDEvent is the Response for an User Event.

# Interfaces

Context interface.

# Type aliases

OperationType is used as an enum to catgorize the various operations in the APIs lifecycle.
ReconnectionPolicy is used as an enum to catgorize the reconnection policies.
StatusCategory is used as an enum to catgorize the various status events in the APIs lifecycle.
WPSChannelMembersInclude is used as an enum to catgorize the available Members include types.
WPSChannelMetadataInclude is used as an enum to catgorize the available Channel include types.
WPSGrantBitMask is the type for perms BitMask.
WPSGrantType grant types.
WPSMembershipsInclude is used as an enum to catgorize the available Memberships include types.
WPSMessageActionsEventType is used as an enum to catgorize the available Message Actions Event types.
WPSMessageType is used as an enum to catgorize the Subscribe response.
WPSObjectsEvent is used as an enum to catgorize the available Object Events.
WPSObjectsEventType is used as an enum to catgorize the available Object Event types.
WPSPushEnvironment is used as an enum to catgorize the available Message Actions Event types.
WPSPushType is used as an enum to catgorize the available Push Types.
WPSResourceType grant types.
WPSUUIDMetadataInclude is used as an enum to catgorize the available UUID include types.