本文整理汇总了Golang中github.com/pubnub/go/pubnubMessaging.PubnubInit函数的典型用法代码示例。如果您正苦于以下问题:Golang PubnubInit函数的具体用法?Golang PubnubInit怎么用?Golang PubnubInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PubnubInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DetailedHistoryFor10Messages
// DetailedHistoryFor10Messages is a common method used by both TestDetailedHistoryFor10EncryptedMessages
// and TestDetailedHistoryFor10Messages to publish's 10 messages to a pubnub channel, and after that
// call the history method of the pubnubMessaging package to fetch last 10 messages. These received
// messages are compared to the messages sent and if all match test is successful.
func DetailedHistoryFor10Messages(t *testing.T, cipherKey string, testName string) {
numberOfMessages := 10
startMessagesFrom := 0
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", cipherKey, false, "")
message := "Test Message "
channel := "testChannel"
messagesSent := PublishMessages(pubnubInstance, channel, t, startMessagesFrom, numberOfMessages, message)
if messagesSent {
returnHistoryChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.History(channel, numberOfMessages, 0, 0, false, returnHistoryChannel, errorChannel)
go ParseHistoryResponseForMultipleMessages(returnHistoryChannel, channel, message, testName, startMessagesFrom, numberOfMessages, cipherKey, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, testName)
} else {
t.Error("Test '" + testName + "': failed.")
}
}
示例2: TestLargeMessage
// TestLargeMessage tests the client by publshing a large message
// An error "message to large" should be returned from the server
func TestLargeMessage(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
channel := "testChannel"
message := "This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. "
returnChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
go ParseLargeResponse("Message Too Large", errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "MessageTooLarge")
}
示例3: TestServerTime
// TestServerTime calls the GetTime method of the pubnubMessaging to test the time
func TestServerTime(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
returnTimeChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.GetTime(returnTimeChannel, errorChannel)
go ParseTimeResponse(returnTimeChannel, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "Time")
}
示例4: DetailedHistoryParamsFor10Messages
// DetailedHistoryFor10Messages is a common method used by both TestDetailedHistoryFor10EncryptedMessages
// and TestDetailedHistoryFor10Messages to publish's 10 messages to a pubnub channel, and after that
// call the history method of the pubnubMessaging package to fetch last 10 messages with time parameters
// between which the messages were sent. These received message is compared to the messages sent and
// if all match test is successful.
func DetailedHistoryParamsFor10Messages(t *testing.T, cipherKey string, secretKey string, testName string) {
numberOfMessages := 5
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", secretKey, cipherKey, false, "")
message := "Test Message "
channel := "testChannel"
startTime := GetServerTime(pubnubInstance, t, testName)
startMessagesFrom := 0
messagesSent := PublishMessages(pubnubInstance, channel, t, startMessagesFrom, numberOfMessages, message)
midTime := GetServerTime(pubnubInstance, t, testName)
startMessagesFrom = 5
messagesSent2 := PublishMessages(pubnubInstance, channel, t, startMessagesFrom, numberOfMessages, message)
endTime := GetServerTime(pubnubInstance, t, testName)
startMessagesFrom = 0
if messagesSent {
returnHistoryChannel := make(chan []byte)
responseChannel := make(chan string)
errorChannel := make(chan []byte)
waitChannel := make(chan string)
go pubnubInstance.History(channel, numberOfMessages, startTime, midTime, false, returnHistoryChannel, errorChannel)
go ParseHistoryResponseForMultipleMessages(returnHistoryChannel, channel, message, testName, startMessagesFrom, numberOfMessages, cipherKey, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, testName)
} else {
t.Error("Test '" + testName + "': failed.")
}
startMessagesFrom = 5
if messagesSent2 {
returnHistoryChannel2 := make(chan []byte)
errorChannel2 := make(chan []byte)
responseChannel2 := make(chan string)
waitChannel2 := make(chan string)
go pubnubInstance.History(channel, numberOfMessages, midTime, endTime, false, returnHistoryChannel2, errorChannel2)
go ParseHistoryResponseForMultipleMessages(returnHistoryChannel2, channel, message, testName, startMessagesFrom, numberOfMessages, cipherKey, responseChannel2)
go ParseErrorResponse(errorChannel2, responseChannel2)
go WaitForCompletion(responseChannel2, waitChannel2)
ParseWaitResponse(waitChannel2, t, testName)
} else {
t.Error("Test '" + testName + "': failed.")
}
}
示例5: TestSubscriptionConnectStatus
// TestSubscriptionConnectStatus sends out a subscribe request to a pubnub channel
// and validates the response for the connect status.
func TestSubscriptionConnectStatus(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
channel := "testChannel"
returnSubscribeChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Subscribe(channel, "", returnSubscribeChannel, false, errorChannel)
go ParseSubscribeResponse(pubnubInstance, returnSubscribeChannel, t, channel, "", "SubscriptionConnectStatus", "", responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "SubscriptionConnectStatus")
}
示例6: HereNow
// HereNow is a common method used by the tests TestHereNow, HereNowWithCipher, CustomUuid
// It subscribes to a pubnub channel and then
// makes a call to the herenow method of the pubnub api.
func HereNow(t *testing.T, cipherKey string, customUuid string, testName string) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", cipherKey, false, customUuid)
channel := "testChannel"
returnSubscribeChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Subscribe(channel, "", returnSubscribeChannel, false, errorChannel)
go ParseSubscribeResponseForPresence(pubnubInstance, customUuid, returnSubscribeChannel, channel, testName, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, testName)
}
示例7: TestEncryptedDetailedHistory
// TestEncryptedDetailedHistory publish's an encrypted message to a pubnub channel and when the
// sent response is received, calls the history method of the pubnubMessaging package to fetch
// 1 message. This received message is compared to the message sent and if both match test is successful.
func TestEncryptedDetailedHistory(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "enigma", false, "")
channel := "testChannel"
message := "Test Message"
returnPublishChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, message, returnPublishChannel, errorChannel)
go ParseResponse(returnPublishChannel, pubnubInstance, channel, message, "EncryptedDetailedHistory", 1, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "EncryptedDetailedHistory")
}
示例8: TestSuccessCodeAndInfoWithEncryption
// TestSuccessCodeAndInfoWithEncryption sends out an encrypted
// message to the pubnub channel
// The response is parsed and should match the 'sent' status.
// _publishSuccessMessage is defined in the common.go file
func TestSuccessCodeAndInfoWithEncryption(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "enigma", false, "")
channel := "testChannel"
message := "Pubnub API Usage Example"
returnChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
go ParsePublishResponse(returnChannel, channel, _publishSuccessMessage, "SuccessCodeAndInfoWithEncryption", responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "SuccessCodeAndInfoWithEncryption")
time.Sleep(2 * time.Second)
}
示例9: TestPresence
// TestPresence subscribes to the presence notifications on a pubnub channel and
// then subscribes to a pubnub channel. The test waits till we get a response from
// the subscribe call. The method that parses the presence response sets the global
// variable _endPresenceTestAsSuccess to true if the presence contains a join info
// on the channel and _endPresenceTestAsFailure is otherwise.
func TestPresence(t *testing.T) {
customUuid := "customuuid"
testName := "Presence"
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, customUuid)
channel := "testForPresenceChannel"
returnPresenceChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Subscribe(channel, "", returnPresenceChannel, true, errorChannel)
go ParseSubscribeResponseForPresence(pubnubInstance, customUuid, returnPresenceChannel, channel, testName, responseChannel)
go ParseResponseDummy(errorChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, testName)
}
示例10: TestMultiSubscriptionConnectStatus
// TestMultiSubscriptionConnectStatus send out a pubnub multi channel subscribe request and
// parses the response for multiple connection status.
func TestMultiSubscriptionConnectStatus(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
testName := "TestMultiSubscriptionConnectStatus"
channels := "testChannel1,testChannel2"
returnSubscribeChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Subscribe(channels, "", returnSubscribeChannel, false, errorChannel)
go ParseSubscribeResponseForMultipleChannels(returnSubscribeChannel, channels, testName, responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, testName)
}
示例11: TestUnsubscribeNotSubscribed
// TestUnsubscribeNotSubscribed will try to unsubscribe a non subscribed pubnub channel.
// The response should contain 'not subscribed'
func TestUnsubscribeNotSubscribed(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
currentTime := time.Now()
channel := "testChannel" + currentTime.Format("20060102150405")
returnUnsubscribeChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Unsubscribe(channel, returnUnsubscribeChannel, errorChannel)
go ParseUnsubscribeResponse(returnUnsubscribeChannel, channel, "not subscribed", responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "UnsubscribeNotSubscribed")
}
示例12: SendMultipleResponse
// SendMultipleResponse is the common implementation for TestMultipleResponsed and
// TestMultipleResponseEncrypted
func SendMultipleResponse(t *testing.T, encrypted bool) {
cipher := ""
testName := "TestMultipleResponse"
if encrypted {
cipher = "enigma"
testName = "TestMultipleResponseEncrypted"
}
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", cipher, false, "")
pubnubChannel := "testChannel"
returnTimeChannel := make(chan []byte)
errorChannelTime := make(chan []byte)
go pubnubInstance.GetTime(returnTimeChannel, errorChannelTime)
retTime, errTime := ParseTimeFromServer(returnTimeChannel, errorChannelTime)
if errTime == nil {
message1 := "message1"
message2 := "message2"
returnPublishChannel := make(chan []byte)
errorChannelPub := make(chan []byte)
go pubnubInstance.Publish(pubnubChannel, message1, returnPublishChannel, errorChannelPub)
b1, _ := ParsePublishResponseFromServer(returnPublishChannel, errorChannelPub)
returnPublishChannel2 := make(chan []byte)
errorChannelPub2 := make(chan []byte)
go pubnubInstance.Publish(pubnubChannel, message2, returnPublishChannel2, errorChannelPub2)
b2, _ := ParsePublishResponseFromServer(returnPublishChannel2, errorChannelPub2)
if b1 && b2 {
returnSubscribeChannel := make(chan []byte)
errorChannelSub := make(chan []byte)
responseChannelSub := make(chan string)
waitChannelSub := make(chan string)
go pubnubInstance.Subscribe(pubnubChannel, retTime, returnSubscribeChannel, false, errorChannelSub)
go ParseSubscribeMultiResponse(pubnubChannel, returnSubscribeChannel, message1, message2, cipher, testName, responseChannelSub)
go ParseErrorResponse(errorChannelSub, responseChannelSub)
go WaitForCompletion(responseChannelSub, waitChannelSub)
ParseWaitResponse(waitChannelSub, t, testName)
}
}
}
示例13: TestNullMessage
// TestNullMessage sends out a null message to a pubnub channel. The response should
// be an "Invalid Message".
func TestNullMessage(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
channel := "testChannel"
var message interface{}
message = nil
returnChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
//go ParsePublishResponse(returnChannel, channel, "Invalid Message", "NullMessage", responseChannel)
go ParseResponseDummy(returnChannel)
go ParseErrorResponseForTestSuccess("Invalid Message", errorChannel, responseChannel)
//go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "NullMessage")
}
示例14: TestSuccessCodeAndInfoForComplexMessage2
// TestSuccessCodeAndInfoForComplexMessage2 sends out a complex message to the pubnub channel
// The response is parsed and should match the 'sent' status.
// _publishSuccessMessage and InitComplexMessage is defined in the common.go file
func TestSuccessCodeAndInfoForComplexMessage2(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
channel := "testChannel"
customComplexMessage := InitComplexMessage()
returnChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, customComplexMessage, returnChannel, errorChannel)
go ParsePublishResponse(returnChannel, channel, _publishSuccessMessage, "SuccessCodeAndInfoForComplexMessage2", responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "SuccessCodeAndInfoForComplexMessage2")
time.Sleep(2 * time.Second)
}
示例15: TestSuccessCodeAndInfoForComplexMessage
// TestSuccessCodeAndInfoForComplexMessage sends out a complex message to the pubnub channel
// The response is parsed and should match the 'sent' status.
// _publishSuccessMessage and customstruct is defined in the common.go file
func TestSuccessCodeAndInfoForComplexMessage(t *testing.T) {
pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
channel := "testChannel"
customStruct := CustomStruct{
Foo: "hi!",
Bar: []int{1, 2, 3, 4, 5},
}
returnChannel := make(chan []byte)
errorChannel := make(chan []byte)
responseChannel := make(chan string)
waitChannel := make(chan string)
go pubnubInstance.Publish(channel, customStruct, returnChannel, errorChannel)
go ParsePublishResponse(returnChannel, channel, _publishSuccessMessage, "SuccessCodeAndInfoForComplexMessage", responseChannel)
go ParseErrorResponse(errorChannel, responseChannel)
go WaitForCompletion(responseChannel, waitChannel)
ParseWaitResponse(waitChannel, t, "SuccessCodeAndInfoForComplexMessage")
time.Sleep(2 * time.Second)
}