本文整理匯總了Golang中github.com/cloudfoundry/gorouter/route.EndpointIterator類的典型用法代碼示例。如果您正苦於以下問題:Golang EndpointIterator類的具體用法?Golang EndpointIterator怎麽用?Golang EndpointIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了EndpointIterator類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serveWebSocket
func (h *RequestHandler) serveWebSocket(iter route.EndpointIterator) error {
var err error
var connection net.Conn
client, _, err := h.hijack()
if err != nil {
return err
}
defer func() {
client.Close()
if connection != nil {
connection.Close()
}
}()
retry := 0
for {
endpoint := iter.Next()
if endpoint == nil {
h.reporter.CaptureBadGateway(h.request)
err = noEndpointsAvailable
h.HandleBadGateway(err)
return err
}
connection, err = net.DialTimeout("tcp", endpoint.CanonicalAddr(), 5*time.Second)
if err == nil {
h.setupRequest(endpoint)
break
}
iter.EndpointFailed()
h.StenoLogger.Set("Error", err.Error())
h.StenoLogger.Warn("proxy.websocket.failed")
retry++
if retry == maxRetries {
return err
}
}
if connection != nil {
err = h.request.Write(connection)
if err != nil {
return err
}
forwardIO(client, connection)
}
return nil
}
示例2: serveTcp
func (h *RequestHandler) serveTcp(iter route.EndpointIterator) error {
var err error
var connection net.Conn
client, _, err := h.hijack()
if err != nil {
return err
}
defer func() {
client.Close()
if connection != nil {
connection.Close()
}
}()
retry := 0
for {
endpoint := iter.Next()
if endpoint == nil {
h.reporter.CaptureBadGateway(h.request)
err = noEndpointsAvailable
h.HandleBadGateway(err)
return err
}
connection, err = net.DialTimeout("tcp", endpoint.CanonicalAddr(), 5*time.Second)
if err == nil {
break
}
iter.EndpointFailed()
h.logger.Error("tcp-connection-failed", err)
retry++
if retry == maxRetries {
return err
}
}
if connection != nil {
forwardIO(client, connection)
}
return nil
}