當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.CloseWithStatus方法代碼示例

本文整理匯總了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
	}
}
開發者ID:pxie,項目名稱:loggregator,代碼行數:10,代碼來源:http_server.go

示例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
	}
}
開發者ID:james-masson,項目名稱:loggregator,代碼行數:11,代碼來源:websocket_server.go

示例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()
}
開發者ID:pxie,項目名稱:loggregator,代碼行數:16,代碼來源:http_server.go

示例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()
}
開發者ID:pxie,項目名稱:loggregator,代碼行數:16,代碼來源:http_server.go

示例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()
}
開發者ID:james-masson,項目名稱:loggregator,代碼行數:16,代碼來源:websocket_server.go

示例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)
}
開發者ID:narayana1208,項目名稱:loggregator,代碼行數:32,代碼來源:sink_server.go

示例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()
}
開發者ID:uabassguy,項目名稱:loggregator,代碼行數:23,代碼來源:http_server.go

示例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()
}
開發者ID:james-masson,項目名稱:loggregator,代碼行數:24,代碼來源:websocket_server.go


注:本文中的code/google/com/p/go/net/websocket.Conn.CloseWithStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。