本文整理匯總了Golang中github.com/lib/pq.Listener.Ping方法的典型用法代碼示例。如果您正苦於以下問題:Golang Listener.Ping方法的具體用法?Golang Listener.Ping怎麽用?Golang Listener.Ping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lib/pq.Listener
的用法示例。
在下文中一共展示了Listener.Ping方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: waitForNotification
func waitForNotification(l *pq.Listener) {
for {
select {
case notify := <-l.Notify:
payload := strings.SplitN(notify.Extra, "|", 3)
id, err := strconv.ParseInt(payload[0], 10, 64)
if err != nil {
panic(err)
}
var roomId int64
roomId, err = strconv.ParseInt(payload[1], 10, 64)
if err != nil {
panic(err)
}
msg := models.GetMessage(id)
revel.INFO.Printf("received notification with payload: '%d' '%d' '%s' '%s'\n", msg.Id, msg.RoomId, msg.Text, msg.ImageUrl)
Publish(EVENT_MSG, int64(roomId), *msg)
case <-time.After(200 * time.Millisecond):
go func() {
if err := l.Ping(); err != nil {
panic(err)
}
}()
}
}
}
示例2: waitForNotification
func waitForNotification(l *pq.Listener) {
for {
select {
case n := <-l.Notify:
fmt.Println("Received data from channel [", n.Channel, "] :")
// Prepare notification payload for pretty print
var prettyJSON bytes.Buffer
err := json.Indent(&prettyJSON, []byte(n.Extra), "", "\t")
if err != nil {
fmt.Println("Error processing JSON: ", err)
return
}
fmt.Println(string(prettyJSON.Bytes()))
return
case <-time.After(90 * time.Second):
fmt.Println("Received no events for 90 seconds, checking connection")
go func() {
l.Ping()
}()
return
}
}
}