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


Golang AccessLogRecord.Response方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/gorouter/access_log.AccessLogRecord.Response方法的典型用法代碼示例。如果您正苦於以下問題:Golang AccessLogRecord.Response方法的具體用法?Golang AccessLogRecord.Response怎麽用?Golang AccessLogRecord.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/gorouter/access_log.AccessLogRecord的用法示例。


在下文中一共展示了AccessLogRecord.Response方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ServeHTTP

func (proxy *Proxy) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
	startedAt := time.Now()
	originalURL := request.URL
	request.URL = &url.URL{Host: originalURL.Host, Opaque: request.RequestURI}
	handler := NewRequestHandler(request, responseWriter)

	accessLog := access_log.AccessLogRecord{
		Request:   request,
		StartedAt: startedAt,
	}

	defer func() {
		proxy.AccessLogger.Log(accessLog)
	}()

	if !isProtocolSupported(request) {
		handler.HandleUnsupportedProtocol()
		return
	}

	if isLoadBalancerHeartbeat(request) {
		handler.HandleHeartbeat()
		return
	}

	routeEndpoint, found := proxy.Lookup(request)
	if !found {
		proxy.Varz.CaptureBadRequest(request)
		handler.HandleMissingRoute()
		return
	}

	handler.logger.Set("RouteEndpoint", routeEndpoint.ToLogData())

	accessLog.RouteEndpoint = routeEndpoint

	proxy.Varz.CaptureRoutingRequest(routeEndpoint, handler.request)

	if isTcpUpgrade(request) {
		handler.HandleTcpRequest(routeEndpoint)
		return
	}

	if isWebSocketUpgrade(request) {
		handler.HandleWebSocketRequest(routeEndpoint)
		return
	}

	endpointResponse, err := handler.HandleHttpRequest(proxy.Transport, routeEndpoint)

	latency := time.Since(startedAt)

	proxy.Registry.CaptureRoutingRequest(routeEndpoint, startedAt)
	proxy.Varz.CaptureRoutingResponse(routeEndpoint, endpointResponse, latency)

	if err != nil {
		proxy.Varz.CaptureBadGateway(request)
		handler.HandleBadGateway(err)
		return
	}

	accessLog.FirstByteAt = time.Now()
	accessLog.Response = endpointResponse

	if proxy.Config.TraceKey != "" && request.Header.Get(VcapTraceHeader) == proxy.Config.TraceKey {
		handler.SetTraceHeaders(proxy.Config.Ip, routeEndpoint.CanonicalAddr())
	}

	bytesSent := handler.WriteResponse(endpointResponse)

	accessLog.FinishedAt = time.Now()
	accessLog.BodyBytesSent = bytesSent
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:73,代碼來源:proxy.go


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