本文整理匯總了Golang中code/google/com/p/go/net/websocket.Conn.CloseWithStatus方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.CloseWithStatus方法的具體用法?Golang Conn.CloseWithStatus怎麽用?Golang Conn.CloseWithStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.CloseWithStatus方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: websocketRouter
func (httpServer *httpServer) websocketRouter(ws *websocket.Conn) {
if ws.Request().URL.Path == TAIL_PATH {
httpServer.websocketSinkHandler(ws)
} else if ws.Request().URL.Path == DUMP_PATH {
httpServer.dumpSinkHandler(ws)
} else {
ws.CloseWithStatus(400)
return
}
}
示例2: route
func (websocketServer *websocketServer) route(ws *websocket.Conn) {
switch ws.Request().URL.Path {
case TAIL_LOGS_PATH:
websocketServer.streamLogs(ws)
case RECENT_LOGS_PATH:
websocketServer.recentLogs(ws)
default:
ws.CloseWithStatus(400)
return
}
}
示例3: dumpSinkHandler
func (httpServer *httpServer) dumpSinkHandler(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
if appId == "" {
httpServer.logInvalidApp(clientAddress)
ws.CloseWithStatus(4000)
return
}
dumpChan := httpServer.messageRouter.getDumpChanFor(appId)
dumpMessagesFromChannelToWebsocket(dumpChan, ws, clientAddress, httpServer.logger)
ws.Close()
}
示例4: websocketSinkHandler
func (httpServer *httpServer) websocketSinkHandler(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
if appId == "" {
httpServer.logInvalidApp(clientAddress)
ws.CloseWithStatus(4000)
return
}
s := sinks.NewWebsocketSink(appId, httpServer.logger, ws, clientAddress, httpServer.messageRouter.sinkCloseChan, httpServer.keepAliveInterval, httpServer.wSMessageBufferSize)
httpServer.logger.Debugf("HttpServer: Requesting a wss sink for app %s", s.AppId())
httpServer.messageRouter.sinkOpenChan <- s
s.Run()
}
示例5: recentLogs
func (websocketServer *websocketServer) recentLogs(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
if appId == "" {
websocketServer.logInvalidApp(clientAddress)
ws.CloseWithStatus(4000)
return
}
logMessages := websocketServer.sinkManager.recentLogsFor(appId)
sendMessagesToWebsocket(logMessages, ws, clientAddress, websocketServer.logger)
ws.Close()
}
示例6: sinkRelayHandler
func (sinkServer *sinkServer) sinkRelayHandler(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
authToken := ws.Request().Header.Get("Authorization")
if appId == "" {
message := fmt.Sprintf("SinkServer: Did not accept sink connection with invalid app id: %s.", clientAddress)
sinkServer.logger.Warn(message)
ws.CloseWithStatus(4000)
return
}
if authToken == "" {
message := fmt.Sprintf("SinkServer: Did not accept sink connection from %s without authorization.", clientAddress)
sinkServer.logger.Warnf(message)
ws.CloseWithStatus(4001)
return
}
if !sinkServer.authorize(authToken, appId, sinkServer.logger) {
message := fmt.Sprintf("SinkServer: Auth token [%s] not authorized to access appId [%s].", authToken, appId)
sinkServer.logger.Warn(message)
ws.CloseWithStatus(4002)
return
}
s := sinks.NewWebsocketSink(appId, sinkServer.logger, ws, clientAddress, sinkServer.keepAliveInterval)
sinkServer.activeSinksChans.Register(s.Channel(), appId)
s.Run(sinkServer.sinkCloseChan)
}
示例7: dumpSinkHandler
func (httpServer *httpServer) dumpSinkHandler(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
if appId == "" {
httpServer.logInvalidApp(clientAddress)
ws.CloseWithStatus(4000)
return
}
dumpChan := httpServer.messageRouter.registerDumpChan(appId)
for message := range dumpChan {
err := websocket.Message.Send(ws, message.GetRawMessage())
if err != nil {
httpServer.logger.Debugf("Dump Sink %s: Error when trying to send data to sink %s. Requesting close. Err: %v", clientAddress, err)
} else {
httpServer.logger.Debugf("Dump Sink %s: Successfully sent data", clientAddress)
}
}
ws.Close()
}
示例8: streamLogs
func (websocketServer *websocketServer) streamLogs(ws *websocket.Conn) {
clientAddress := ws.RemoteAddr()
appId := appid.FromUrl(ws.Request().URL)
if appId == "" {
websocketServer.logInvalidApp(clientAddress)
ws.CloseWithStatus(4000)
return
}
websocketSink := sinks.NewWebsocketSink(
appId,
websocketServer.logger,
ws,
clientAddress,
websocketServer.sinkManager.sinkCloseChan,
websocketServer.keepAliveInterval,
websocketServer.bufferSize,
)
websocketServer.logger.Debugf("WebsocketServer: Requesting a wss sink for app %s", websocketSink.AppId())
websocketServer.sinkManager.sinkOpenChan <- websocketSink
websocketSink.Run()
}