Documentation ¶
Overview ¶
Package messaging provides the implemetation to connect to pubnub api on google appengine. Build Date: Jul 30, 2015 Version: 3.7.0
Index ¶
- Variables
- func DecryptString(cipherKey string, message string) (retVal interface{}, err error)
- func DeleteSession(context context.Context, w http.ResponseWriter, r *http.Request, secKey string)
- func EncryptString(cipherKey string, message string) string
- func GenUuid() (string, error)
- func GetNonSubscribeTimeout() uint16
- func GetSessionsOptionsObject(age int) *sessions.Options
- func GetSubscribeTimeout() uint16
- func ParseInterfaceData(myInterface interface{}) string
- func ParseJSON(contents []byte, cipherKey string) (string, string, string, error)
- func SetConnectTimeout(val uint16)
- func SetIV(val string)
- func SetMaxRetries(val int)
- func SetNonSubscribeTimeout(val uint16)
- func SetOrigin(val string)
- func SetResumeOnReconnect(val bool)
- func SetRetryInterval(val uint16)
- func SetSessionKeys(context context.Context, w http.ResponseWriter, r *http.Request, pubKey string, ...)
- func SetSubscribeTimeout(val uint16)
- func VersionInfo() string
- type Pubnub
- func (pub *Pubnub) AuditChannelGroup(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) AuditPresence(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) AuditSubscribe(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) ChannelGroupAddChannel(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) ChannelGroupListChannels(context context.Context, w http.ResponseWriter, r *http.Request, group string, ...)
- func (pub *Pubnub) ChannelGroupRemoveChannel(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) ChannelGroupRemoveGroup(context context.Context, w http.ResponseWriter, r *http.Request, group string, ...)
- func (pub *Pubnub) CloseExistingConnection()
- func (pub *Pubnub) GetAuthenticationKey() string
- func (pub *Pubnub) GetPresenceHeartbeatInterval() uint16
- func (pub *Pubnub) GetTime(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) GetUUID() string
- func (pub *Pubnub) GetUserState(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) GlobalHereNow(context context.Context, w http.ResponseWriter, r *http.Request, showUuid bool, ...)
- func (pub *Pubnub) GrantChannelGroup(context context.Context, w http.ResponseWriter, r *http.Request, group string, ...)
- func (pub *Pubnub) GrantPresence(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) GrantSubscribe(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) HereNow(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) History(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) Publish(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) PublishExtended(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) SetAuthenticationKey(context context.Context, w http.ResponseWriter, r *http.Request, val string)
- func (pub *Pubnub) SetUUID(context context.Context, w http.ResponseWriter, r *http.Request, val string)
- func (pub *Pubnub) SetUserStateJSON(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) SetUserStateKeyVal(context context.Context, w http.ResponseWriter, r *http.Request, ...)
- func (pub *Pubnub) WhereNow(context context.Context, w http.ResponseWriter, r *http.Request, uuid string, ...)
- type PubnubUnitTest
Constants ¶
This section is empty.
Variables ¶
var Store *sessions.CookieStore
Store for storing a ref of CookieStore
Functions ¶
func DecryptString ¶
DecryptString decodes encrypted string using the cipherKey
It accepts the following parameters: cipherKey: cipher key to use to decrypt. message: to encrypted.
returns the unencoded encrypted string, error if any.
func DeleteSession ¶
DeleteSession deletes the session that stores the pubInstance it accepts
context.Context http.ResponseWriter *http.Request secret Key
func EncryptString ¶
EncryptString creates the base64 encoded encrypted string using the cipherKey. It accepts the following parameters: cipherKey: cipher key to use to encrypt. message: to encrypted.
returns the base64 encoded encrypted string.
func GetNonSubscribeTimeout ¶
func GetNonSubscribeTimeout() uint16
GetNonSubscribeTimeout gets the value of nonSubscribeTimeout
func GetSessionsOptionsObject ¶
GetSessionsOptionsObject sets common Path, Age and HttpOnly options for the sessions. It returns the *sessions.Options object
func GetSubscribeTimeout ¶
func GetSubscribeTimeout() uint16
GetSubscribeTimeout gets the value of subscribeTimeout
func ParseInterfaceData ¶
func ParseInterfaceData(myInterface interface{}) string
ParseInterfaceData formats the data to string as per the type of the data.
It accepts the following parameters: myInterface: the interface data to parse and convert to string.
returns: the data in string format.
func ParseJSON ¶
ParseJSON parses the json data. It extracts the actual data (value 0), Timetoken/from time in case of detailed history (value 1), pubnub channelname/timetoken/to time in case of detailed history (value 2).
It accepts the following parameters: contents: the contents to parse. cipherKey: the key to decrypt the messages (can be empty).
returns: data: as string. Timetoken/from time in case of detailed history as string. pubnub channelname/timetoken/to time in case of detailed history (value 2). error if any.
func SetConnectTimeout ¶
func SetConnectTimeout(val uint16)
SetConnectTimeout sets the value of connectTimeout.
func SetNonSubscribeTimeout ¶
func SetNonSubscribeTimeout(val uint16)
SetNonSubscribeTimeout sets the value of nonsubscribeTimeout.
func SetOrigin ¶
func SetOrigin(val string)
SetOrigin sets the value of _origin. Should be called before PubnubInit
func SetResumeOnReconnect ¶
func SetResumeOnReconnect(val bool)
SetResumeOnReconnect sets the value of resumeOnReconnect.
func SetRetryInterval ¶
func SetRetryInterval(val uint16)
SetRetryInterval sets the value of retryInterval.
func SetSessionKeys ¶
func SetSessionKeys(context context.Context, w http.ResponseWriter, r *http.Request, pubKey string, subKey string, secKey string, cipher string, ssl bool, uuid string)
SetSessionKeys initializes the Pubnub instance using the new Pubnub key. This is similar to New but in used to change the keys once the pubnub instance has been initialized it accepts
context.Context http.ResponseWriter *http.Request publishKey subscribeKey secretKey cipher ssl uuid
func SetSubscribeTimeout ¶
func SetSubscribeTimeout(val uint16)
SetSubscribeTimeout sets the value of subscribeTimeout.
func VersionInfo ¶
func VersionInfo() string
VersionInfo returns the version of the this code along with the build date.
Types ¶
type Pubnub ¶
type Pubnub struct { Origin string PublishKey string SubscribeKey string SecretKey string CipherKey string AuthenticationKey string IsSSL bool Uuid string TimeToken string SentTimeToken string ResetTimeToken bool UserState map[string]map[string]interface{} // contains filtered or unexported fields }
Pubnub structure. origin stores the root url value of pubnub api in the current instance. publishKey stores the user specific Publish Key in the current instance. subscribeKey stores the user specific Subscribe Key in the current instance. secretKey stores the user specific Secret Key in the current instance. cipherKey stores the user specific Cipher Key in the current instance. authenticationKey stores the Authentication Key in the current instance. isSSL is true if enabled, else is false for the current instance. uuid is the unique identifier, it can be a custom value or is automatically generated. subscribedChannels keeps a list of subscribed Pubnub channels by the user in the a comma separated string. timeToken is the current value of the servertime. This will be used to appened in each request. sentTimeToken: This is the timetoken sent to the server with the request resetTimeToken: In case of a new request or an error this variable is set to true so that the timeToken will be set to 0 in the next request. presenceChannels: All the presence responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. subscribeChannels: All the subscribe responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. presenceErrorChannels: All the presence error responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. subscribeErrorChannels: All the subscribe error responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. newSubscribedChannels keeps a list of the new subscribed Pubnub channels by the user in the a comma separated string, before they are appended to the Pubnub SubscribedChannels. isPresenceHeartbeatRunning a variable to keep a check on the presence heartbeat's status Mutex to lock the operations on the instance
func New ¶
func New(context context.Context, uuid string, w http.ResponseWriter, r *http.Request, publishKey string, subscribeKey string, secretKey string, cipher string, ssl bool) *Pubnub
New initializes the Session and the Pubnub instance. It accepts:
context.Context uuid http.ResponseWriter *http.Request publishKey subscribeKey secretKey cipher ssl
It returns the Pubnub Instance
func NewPubnub ¶
func NewPubnub(context context.Context, w http.ResponseWriter, r *http.Request, publishKey string, subscribeKey string, secretKey string, cipherKey string, sslOn bool, customUuid string) *Pubnub
NewPubnub initializes pubnub struct with the user provided values. And then initiates the origin by appending the protocol based upon the sslOn argument. Then it uses the customuuid or generates the uuid.
It accepts the following parameters: publishKey is the user specific Publish Key. Mandatory. subscribeKey is the user specific Subscribe Key. Mandatory. secretKey is the user specific Secret Key. Accepts empty string if not used. cipherKey stores the user specific Cipher Key. Accepts empty string if not used. sslOn is true if enabled, else is false. customUuid is the unique identifier, it can be a custom value or sent as empty for automatic generation.
returns the pointer to Pubnub instance.
func (*Pubnub) AuditChannelGroup ¶
func (pub *Pubnub) AuditChannelGroup(context context.Context, w http.ResponseWriter, r *http.Request, group, authKey string, callbackChannel, errorChannel chan []byte)
AuditChannelGroup will make a call to display the permissions for a channel group or subkey
func (*Pubnub) AuditPresence ¶
func (pub *Pubnub) AuditPresence(context context.Context, w http.ResponseWriter, r *http.Request, channel, authKey string, callbackChannel, errorChannel chan []byte)
AuditPresence will make a call to display the permissions for a channel or subkey
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) AuditSubscribe ¶
func (pub *Pubnub) AuditSubscribe(context context.Context, w http.ResponseWriter, r *http.Request, channel, authKey string, callbackChannel, errorChannel chan []byte)
AuditSubscribe will make a call to display the permissions for a channel or subkey
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) ChannelGroupAddChannel ¶
func (*Pubnub) ChannelGroupListChannels ¶
func (*Pubnub) ChannelGroupRemoveChannel ¶
func (*Pubnub) ChannelGroupRemoveGroup ¶
func (*Pubnub) CloseExistingConnection ¶
func (pub *Pubnub) CloseExistingConnection()
CloseExistingConnection closes the open subscribe/presence connection.
func (*Pubnub) GetAuthenticationKey ¶
GetAuthenticationKey gets the value of authentication key
func (*Pubnub) GetPresenceHeartbeatInterval ¶
GetPresenceHeartbeatInterval gets the value of presenceHeartbeatInterval
func (*Pubnub) GetTime ¶
func (pub *Pubnub) GetTime(context context.Context, w http.ResponseWriter, r *http.Request, callbackChannel chan []byte, errorChannel chan []byte)
GetTime is the struct Pubnub's instance method that calls the ExecuteTime method to process the time request. . It accepts the following parameters: callbackChannel on which to send the response. errorChannel on which to send the error response.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GetUserState ¶
func (pub *Pubnub) GetUserState(context context.Context, w http.ResponseWriter, r *http.Request, channel string, callbackChannel chan []byte, errorChannel chan []byte)
GetUserState is the struct Pubnub's instance method which creates and posts the GetUserState request to get the connected users details.
It accepts the following parameters: channel: a single value of the pubnub channel. callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GlobalHereNow ¶
func (pub *Pubnub) GlobalHereNow(context context.Context, w http.ResponseWriter, r *http.Request, showUuid bool, includeUserState bool, callbackChannel chan []byte, errorChannel chan []byte)
GlobalHereNow is the struct Pubnub's instance method which creates and posts the globalherenow request to get the connected users details.
It accepts the following parameters: showUuid: if true uuids of devices will be fetched in the respose includeUserState: if true the user states of devices will be fetched in the respose callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GrantChannelGroup ¶
func (pub *Pubnub) GrantChannelGroup(context context.Context, w http.ResponseWriter, r *http.Request, group string, read, manage bool, ttl int, authKey string, callbackChannel, errorChannel chan []byte)
GrantChannelGroup is used to give a channel group read or manage permissions and set TTL values for it.
func (*Pubnub) GrantPresence ¶
func (pub *Pubnub) GrantPresence(context context.Context, w http.ResponseWriter, r *http.Request, channel string, read, write bool, ttl int, authKey string, callbackChannel, errorChannel chan []byte)
GrantPresence is used to give a presence channel read, write permissions and set TTL values for it. To grant a permission set read or write as true to revoke all perms set read and write false and ttl as -1
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GrantSubscribe ¶
func (pub *Pubnub) GrantSubscribe(context context.Context, w http.ResponseWriter, r *http.Request, channel string, read, write bool, ttl int, authKey string, callbackChannel, errorChannel chan []byte)
GrantSubscribe is used to give a subscribe channel read, write permissions and set TTL values for it. To grant a permission set read or write as true to revoke all perms set read and write false and ttl as -1
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) HereNow ¶
func (pub *Pubnub) HereNow(context context.Context, w http.ResponseWriter, r *http.Request, channel string, showUuid bool, includeUserState bool, callbackChannel chan []byte, errorChannel chan []byte)
HereNow is the struct Pubnub's instance method which creates and posts the herenow request to get the connected users details.
It accepts the following parameters: channel: a single value of the pubnub channel. callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) History ¶
func (pub *Pubnub) History(context context.Context, w http.ResponseWriter, r *http.Request, channel string, limit int, start int64, end int64, reverse bool, callbackChannel chan []byte, errorChannel chan []byte)
History is the struct Pubnub's instance method which creates and post the History request for a single pubnub channel.
It parses the response to get the data and return it to the channel.
It accepts the following parameters: channel: a single value of the pubnub channel. limit: number of history messages to return. start: start time from where to begin the history messages. end: end time till where to get the history messages. reverse: to fetch the messages in ascending order callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) Publish ¶
func (pub *Pubnub) Publish(context context.Context, w http.ResponseWriter, r *http.Request, channel string, message interface{}, callbackChannel, errorChannel chan []byte)
Publish is the struct Pubnub's instance method that creates a publish request and calls SendPublishRequest to post the request.
It calls the InvalidChannel and InvalidMessage methods to validate the Pubnub channels and message. Calls the GetHmacSha256 to generate a signature if a secretKey is to be used. Creates the publish url Calls json marshal Calls the EncryptString method is the cipherkey is used and calls json marshal Closes the channel after the response is received
It accepts the following parameters: channel: The Pubnub channel to which the message is to be posted. message: message to be posted. callbackChannel: Channel on which to send the response back. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) PublishExtended ¶
func (pub *Pubnub) PublishExtended(context context.Context, w http.ResponseWriter, r *http.Request, channel string, message interface{}, storeInHistory, doNotSerialize bool, callbackChannel, errorChannel chan []byte)
Publish is the struct Pubnub's instance method that creates a publish request and calls SendPublishRequest to post the request.
It calls the InvalidChannel and InvalidMessage methods to validate the Pubnub channels and message. Calls the GetHmacSha256 to generate a signature if a secretKey is to be used. Creates the publish url Calls json marshal Calls the EncryptString method is the cipherkey is used and calls json marshal Closes the channel after the response is received
It accepts the following parameters: channel: The Pubnub channel to which the message is to be posted. message: message to be posted. storeInHistory: Message will be persisted in Storage & Playback db doNotSerialize: Set this option to true if you use your own serializer. In this case passed-in message should be a string or []byte callbackChannel: Channel on which to send the response back. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) SetAuthenticationKey ¶
func (pub *Pubnub) SetAuthenticationKey(context context.Context, w http.ResponseWriter, r *http.Request, val string)
SetAuthenticationKey sets the value of authentication key
func (*Pubnub) SetUUID ¶
func (pub *Pubnub) SetUUID(context context.Context, w http.ResponseWriter, r *http.Request, val string)
SetUUID sets the value of UUID
func (*Pubnub) SetUserStateJSON ¶
func (pub *Pubnub) SetUserStateJSON(context context.Context, w http.ResponseWriter, r *http.Request, channel string, jsonString string, callbackChannel chan []byte, errorChannel chan []byte)
SetUserStateJSON is the struct Pubnub's instance method which creates and posts the User state request using JSON as input
It accepts the following parameters: channel: a single value of the pubnub channel. jsonString: the user state in JSON format. If invalid an error will be thrown callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) SetUserStateKeyVal ¶
func (pub *Pubnub) SetUserStateKeyVal(context context.Context, w http.ResponseWriter, r *http.Request, channel string, key string, val string, callbackChannel chan []byte, errorChannel chan []byte)
SetUserStateKeyVal is the struct Pubnub's instance method which creates and posts the userstate request using a key/val map
It accepts the following parameters: channel: a single value of the pubnub channel. key: user states key value: user stated value callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) WhereNow ¶
func (pub *Pubnub) WhereNow(context context.Context, w http.ResponseWriter, r *http.Request, uuid string, callbackChannel chan []byte, errorChannel chan []byte)
WhereNow is the struct Pubnub's instance method which creates and posts the wherenow request to get the connected users details.
It accepts the following parameters: uuid: devcie uuid to pass to the wherenow query callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
type PubnubUnitTest ¶
type PubnubUnitTest struct { }
PubnubUnitTest structure used to expose some data for unit tests.
func (*PubnubUnitTest) GetSentTimeToken ¶
func (pubtest *PubnubUnitTest) GetSentTimeToken(pub *Pubnub) string
GetSentTimeToken returns the timetoken sent to the server, is used only for unit tests
func (*PubnubUnitTest) GetTimeToken ¶
func (pubtest *PubnubUnitTest) GetTimeToken(pub *Pubnub) string
GetTimeToken returns the latest timetoken received from the server, is used only for unit tests