本文整理汇总了Golang中github.com/cloudfoundry/gorouter/route.Endpoint类的典型用法代码示例。如果您正苦于以下问题:Golang Endpoint类的具体用法?Golang Endpoint怎么用?Golang Endpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Endpoint类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Register
func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
t := time.Now()
data := lager.Data{"uri": uri, "backend": endpoint.CanonicalAddr(), "modification_tag": endpoint.ModificationTag}
r.reporter.CaptureRegistryMessage(endpoint)
r.Lock()
uri = uri.RouteKey()
pool, found := r.byUri.Find(uri)
if !found {
contextPath := parseContextPath(uri)
pool = route.NewPool(r.dropletStaleThreshold/4, contextPath)
r.byUri.Insert(uri, pool)
r.logger.Debug("uri-added", lager.Data{"uri": uri})
}
endpointAdded := pool.Put(endpoint)
r.timeOfLastUpdate = t
r.Unlock()
if endpointAdded {
r.logger.Debug("endpoint-registered", data)
} else {
r.logger.Debug("endpoint-not-registered", data)
}
}
示例2: processBackend
func (p *proxyRoundTripper) processBackend(request *http.Request, endpoint *route.Endpoint) {
p.handler.Logger().Debug("proxy.backend")
request.URL.Host = endpoint.CanonicalAddr()
request.Header.Set("X-CF-ApplicationID", endpoint.ApplicationId)
setRequestXCfInstanceId(request, endpoint)
}
示例3: Register
func (registry *Registry) Register(uri route.Uri, endpoint *route.Endpoint) {
registry.Lock()
defer registry.Unlock()
uri = uri.ToLower()
key := tableKey{
addr: endpoint.CanonicalAddr(),
uri: uri,
}
var endpointToRegister *route.Endpoint
entry, found := registry.table[key]
if found {
endpointToRegister = entry.endpoint
} else {
endpointToRegister = endpoint
entry = &tableEntry{endpoint: endpoint}
registry.table[key] = entry
}
pool, found := registry.byUri[uri]
if !found {
pool = route.NewPool()
registry.byUri[uri] = pool
}
pool.Add(endpointToRegister)
entry.updatedAt = time.Now()
registry.timeOfLastUpdate = time.Now()
}
示例4: serveWebSocket
func (h *RequestHandler) serveWebSocket(endpoint *route.Endpoint) error {
var err error
client, _, err := h.hijack()
if err != nil {
return err
}
connection, err := net.Dial("tcp", endpoint.CanonicalAddr())
if err != nil {
return err
}
defer client.Close()
defer connection.Close()
err = h.request.Write(connection)
if err != nil {
return err
}
forwardIO(client, connection)
return nil
}
示例5: SetRequestXCfInstanceId
func SetRequestXCfInstanceId(request *http.Request, endpoint *route.Endpoint) {
value := endpoint.PrivateInstanceId
if value == "" {
value = endpoint.CanonicalAddr()
}
request.Header.Set(router_http.CfInstanceIdHeader, value)
}
示例6: Unregister
func (registry *Registry) Unregister(uri route.Uri, endpoint *route.Endpoint) {
registry.Lock()
defer registry.Unlock()
uri = uri.ToLower()
key := tableKey{
addr: endpoint.CanonicalAddr(),
uri: uri,
}
registry.unregisterUri(key)
}
示例7: RoundTrip
func (p *proxyRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
var err error
var res *http.Response
var endpoint *route.Endpoint
retry := 0
for {
endpoint = p.iter.Next()
if endpoint == nil {
p.handler.reporter.CaptureBadGateway(request)
err = noEndpointsAvailable
p.handler.HandleBadGateway(err)
return nil, err
}
request.URL.Host = endpoint.CanonicalAddr()
request.Header.Set("X-CF-ApplicationID", endpoint.ApplicationId)
setRequestXCfInstanceId(request, endpoint)
res, err = p.transport.RoundTrip(request)
if err == nil {
break
}
if ne, netErr := err.(*net.OpError); !netErr || ne.Op != "dial" {
break
}
p.iter.EndpointFailed()
p.handler.Logger().Set("Error", err.Error())
p.handler.Logger().Warnf("proxy.endpoint.failed")
retry++
if retry == retries {
break
}
}
if p.after != nil {
p.after(res, endpoint, err)
}
p.response = res
p.err = err
return res, err
}
示例8: TestLookup
func (s *RegistrySuite) TestLookup(c *C) {
m := &route.Endpoint{
Host: "192.168.1.1",
Port: 1234,
}
s.Register("foo", m)
var b *route.Endpoint
var ok bool
b, ok = s.Lookup("foo")
c.Assert(ok, Equals, true)
c.Check(b.CanonicalAddr(), Equals, "192.168.1.1:1234")
b, ok = s.Lookup("FOO")
c.Assert(ok, Equals, true)
c.Check(b.CanonicalAddr(), Equals, "192.168.1.1:1234")
}
示例9: Unregister
func (r *RouteRegistry) Unregister(uri route.Uri, endpoint *route.Endpoint) {
data := lager.Data{"uri": uri, "backend": endpoint.CanonicalAddr(), "modification_tag": endpoint.ModificationTag}
r.reporter.CaptureRegistryMessage(endpoint)
r.Lock()
uri = uri.RouteKey()
pool, found := r.byUri.Find(uri)
if found {
endpointRemoved := pool.Remove(endpoint)
if endpointRemoved {
r.logger.Debug("endpoint-unregistered", data)
} else {
r.logger.Debug("endpoint-not-unregistered", data)
}
if pool.IsEmpty() {
r.byUri.Delete(uri)
}
}
r.Unlock()
}
示例10: setupRequest
func (h *RequestHandler) setupRequest(endpoint *route.Endpoint) {
h.setRequestURL(endpoint.CanonicalAddr())
h.setRequestXForwardedFor()
SetRequestXRequestStart(h.request)
}
示例11: setupRequest
func (rt *BackendRoundTripper) setupRequest(request *http.Request, endpoint *route.Endpoint) {
rt.handler.Logger().Debug("backend")
request.URL.Host = endpoint.CanonicalAddr()
request.Header.Set("X-CF-ApplicationID", endpoint.ApplicationId)
handler.SetRequestXCfInstanceId(request, endpoint)
}
示例12: setupRequest
func (h *RequestHandler) setupRequest(endpoint *route.Endpoint) {
h.setRequestURL(endpoint.CanonicalAddr())
h.setRequestXForwardedFor()
setRequestXRequestStart(h.request)
setRequestXVcapRequestId(h.request, h.StenoLogger)
}
示例13:
dropsondeMetrics "github.com/cloudfoundry/dropsonde/metrics"
"github.com/cloudfoundry/gorouter/metrics"
"net/http"
"time"
"github.com/cloudfoundry/dropsonde/metricbatcher"
"github.com/cloudfoundry/gorouter/route"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("MetricsReporter", func() {
var metricsReporter *metrics.MetricsReporter
var req *http.Request
var endpoint *route.Endpoint
var sender *fake.FakeMetricSender
BeforeEach(func() {
metricsReporter = metrics.NewMetricsReporter()
req, _ = http.NewRequest("GET", "https://example.com", nil)
endpoint = route.NewEndpoint("someId", "host", 2222, "privateId", map[string]string{}, 30, "", models.ModificationTag{})
sender = fake.NewFakeMetricSender()
batcher := metricbatcher.New(sender, time.Millisecond)
dropsondeMetrics.Initialize(sender, batcher)
})
It("increments the bad_requests metric", func() {
metricsReporter.CaptureBadRequest(req)
Eventually(func() uint64 { return sender.GetCounter("rejected_requests") }).Should(BeEquivalentTo(1))