本文整理汇总了Golang中trafficcontroller/listener.NewWebsocket函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWebsocket函数的具体用法?Golang NewWebsocket怎么用?Golang NewWebsocket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWebsocket函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newLegacyWebsocketListener
func newLegacyWebsocketListener(timeout time.Duration, logger *gosteno.Logger) listener.Listener {
return listener.NewWebsocket(marshaller.LoggregatorLogMessage, marshaller.TranslateDropsondeToLegacyLogMessage, timeout, logger)
}
示例2: newDropsondeWebsocketListener
func newDropsondeWebsocketListener(timeout time.Duration, logger *gosteno.Logger) listener.Listener {
messageConverter := func(message []byte) ([]byte, error) {
return message, nil
}
return listener.NewWebsocket(marshaller.DropsondeLogMessage, messageConverter, timeout, logger)
}
示例3:
testhelpers.AlwaysReturn(mockBatcher.BatchCounterOutput, mockChainer)
testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)
messageChan = make(chan []byte)
outputChan = make(chan []byte, 10)
stopChan = make(chan struct{})
fh = &fakeHandler{messages: messageChan}
ts = httptest.NewUnstartedServer(fh)
converter = func(d []byte) ([]byte, error) { return d, nil }
})
JustBeforeEach(func() {
l = listener.NewWebsocket(
marshaller.LoggregatorLogMessage,
converter,
readTimeout,
handshakeTimeout,
mockBatcher,
loggertesthelper.Logger(),
)
})
AfterEach(func() {
select {
case <-messageChan:
// already closed
default:
close(messageChan)
}
ts.Close()
})
示例4:
var _ = Describe("WebsocketListener", func() {
var ts *httptest.Server
var messageChan, outputChan chan []byte
var stopChan chan struct{}
var l listener.Listener
var fh *fakeHandler
BeforeEach(func() {
messageChan = make(chan []byte)
outputChan = make(chan []byte, 10)
stopChan = make(chan struct{})
fh = &fakeHandler{messages: messageChan}
ts = httptest.NewUnstartedServer(fh)
converter := func(d []byte) ([]byte, error) { return d, nil }
l = listener.NewWebsocket(marshaller.LoggregatorLogMessage, converter, 500*time.Millisecond, loggertesthelper.Logger())
})
AfterEach(func() {
select {
case <-messageChan:
// already closed
default:
close(messageChan)
}
ts.Close()
})
Context("when the server is not running", func() {
It("should error when connecting", func(done Done) {
err := l.Start("ws://localhost:1234", "myApp", outputChan, stopChan)