• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang route.Endpoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
	}
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:29,代码来源:registry.go


示例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)
}
开发者ID:simonjohansson,项目名称:gorouter,代码行数:7,代码来源:proxy.go


示例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()
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:35,代码来源:registry.go


示例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
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:25,代码来源:request_handler.go


示例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)
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:8,代码来源:request_handler.go


示例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)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:13,代码来源:registry.go


示例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
}
开发者ID:johannespetzold,项目名称:gorouter,代码行数:48,代码来源:proxy.go


示例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")
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:19,代码来源:registry_test.go


示例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()
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:24,代码来源:registry.go


示例10: setupRequest

func (h *RequestHandler) setupRequest(endpoint *route.Endpoint) {
	h.setRequestURL(endpoint.CanonicalAddr())
	h.setRequestXForwardedFor()
	SetRequestXRequestStart(h.request)
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:5,代码来源:request_handler.go


示例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)
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:6,代码来源:proxy_round_tripper.go


示例12: setupRequest

func (h *RequestHandler) setupRequest(endpoint *route.Endpoint) {
	h.setRequestURL(endpoint.CanonicalAddr())
	h.setRequestXForwardedFor()
	setRequestXRequestStart(h.request)
	setRequestXVcapRequestId(h.request, h.StenoLogger)
}
开发者ID:krumts,项目名称:gorouter,代码行数:6,代码来源:request_handler.go


示例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))
开发者ID:rakutentech,项目名称:gorouter,代码行数:30,代码来源:metrics_reporter_test.go



注:本文中的github.com/cloudfoundry/gorouter/route.Endpoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang route.EndpointIterator类代码示例发布时间:2022-05-23
下一篇:
Golang route.Uri函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap