当前位置: 首页>>代码示例>>Golang>>正文


Golang Endpoint.CanonicalAddr方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/gorouter/route.Endpoint.CanonicalAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Endpoint.CanonicalAddr方法的具体用法?Golang Endpoint.CanonicalAddr怎么用?Golang Endpoint.CanonicalAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/gorouter/route.Endpoint的用法示例。


在下文中一共展示了Endpoint.CanonicalAddr方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例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


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