本文整理匯總了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
}