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


Golang route.Uri函数代码示例

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


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

示例1: deleteEndpoints

func (r *RouteFetcher) deleteEndpoints(validRoutes []db.Route) {
	var diff []db.Route

	for _, curRoute := range r.endpoints {
		routeFound := false

		for _, validRoute := range validRoutes {
			if routeEquals(curRoute, validRoute) {
				routeFound = true
				break
			}
		}

		if !routeFound {
			diff = append(diff, curRoute)
			r.endpoints = r.endpoints
		}
	}

	for _, aRoute := range diff {
		r.RouteRegistry.Unregister(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.TTL,
				aRoute.RouteServiceUrl,
			))
	}
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:33,代码来源:route_fetcher.go

示例2: BenchmarkRegister

func BenchmarkRegister(b *testing.B) {
	c := config.DefaultConfig()
	mbus := fakeyagnats.New()
	r := registry.NewCFRegistry(c, mbus)

	proxy.NewProxy(proxy.ProxyArgs{
		EndpointTimeout: c.EndpointTimeout,
		Ip:              c.Ip,
		TraceKey:        c.TraceKey,
		Registry:        r,
		Reporter:        varz.NewVarz(r),
		Logger:          access_log.CreateRunningAccessLogger(c),
	})

	for i := 0; i < b.N; i++ {
		str := strconv.Itoa(i)

		r.Register(
			route.Uri("bench.vcap.me."+str),
			&route.Endpoint{
				Host: "localhost",
				Port: uint16(i),
			},
		)
	}
}
开发者ID:jackfengibm,项目名称:gorouter,代码行数:26,代码来源:perf_test.go

示例3: registerAddr

func registerAddr(r *registry.RouteRegistry, u string, a net.Addr, instanceId string) {
	h, p, err := net.SplitHostPort(a.String())
	Ω(err).NotTo(HaveOccurred())

	x, err := strconv.Atoi(p)
	Ω(err).NotTo(HaveOccurred())

	r.Register(route.Uri(u), route.NewEndpoint("", h, uint16(x), instanceId, nil))
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:9,代码来源:proxy_test.go

示例4: registerAddr

func registerAddr(reg *registry.RouteRegistry, path string, routeServiceUrl string, addr net.Addr, instanceId string) {
	host, portStr, err := net.SplitHostPort(addr.String())
	Expect(err).NotTo(HaveOccurred())

	port, err := strconv.Atoi(portStr)
	Expect(err).NotTo(HaveOccurred())

	reg.Register(route.Uri(path), route.NewEndpoint("", host, uint16(port), instanceId, nil, -1, routeServiceUrl))
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:9,代码来源:proxy_test.go

示例5: HandleEvent

func (r *RouteFetcher) HandleEvent(e routing_api.Event) {
	eventRoute := e.Route
	uri := route.Uri(eventRoute.Route)
	endpoint := route.NewEndpoint(eventRoute.LogGuid, eventRoute.IP, uint16(eventRoute.Port), eventRoute.LogGuid, nil, eventRoute.TTL, eventRoute.RouteServiceUrl)
	switch e.Action {
	case "Delete":
		r.RouteRegistry.Unregister(uri, endpoint)
	case "Upsert":
		r.RouteRegistry.Register(uri, endpoint)
	}
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:11,代码来源:route_fetcher.go

示例6: lookup

func (p *proxy) lookup(request *http.Request) *route.Pool {
	var requestPath string
	if request.URL.IsAbs() {
		requestPath = request.URL.Path
	} else {
		requestPath = request.RequestURI
	}

	uri := route.Uri(hostWithoutPort(request) + requestPath)
	return p.registry.Lookup(uri)
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:11,代码来源:proxy.go

示例7: HandleEvent

func (r *RouteFetcher) HandleEvent(e routing_api.Event) error {
	r.logger.Infof("Handling event: %v", e)
	eventRoute := e.Route
	uri := route.Uri(eventRoute.Route)
	endpoint := route.NewEndpoint(eventRoute.LogGuid, eventRoute.IP, uint16(eventRoute.Port), eventRoute.LogGuid, nil, eventRoute.TTL)
	switch e.Action {
	case "Delete":
		r.RouteRegistry.Unregister(uri, endpoint)
	case "Upsert":
		r.RouteRegistry.Register(uri, endpoint)
	}

	r.logger.Infof("Successfully handled event: %v", e)
	return nil
}
开发者ID:trainchou,项目名称:gorouter,代码行数:15,代码来源:route_fetcher.go

示例8: Lookup

func (proxy *Proxy) Lookup(request *http.Request) (*route.Endpoint, bool) {
	uri := route.Uri(hostWithoutPort(request))

	// Try choosing a backend using sticky session
	if _, err := request.Cookie(StickyCookieKey); err == nil {
		if sticky, err := request.Cookie(VcapCookieId); err == nil {
			routeEndpoint, ok := proxy.Registry.LookupByPrivateInstanceId(uri, sticky.Value)
			if ok {
				return routeEndpoint, ok
			}
		}
	}

	// Choose backend using host alone
	return proxy.Registry.Lookup(uri)
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:16,代码来源:proxy.go

示例9: toMap

func (r *Trie) toMap(segment string, m map[route.Uri]*route.Pool) map[route.Uri]*route.Pool {
	if r.Pool != nil {
		m[route.Uri(segment)] = r.Pool
	}

	for _, child := range r.ChildNodes {
		var newseg string
		if len(segment) == 0 {
			newseg = segment + child.Segment
		} else {
			newseg = segment + "/" + child.Segment
		}
		child.toMap(newseg, m)
	}

	return m
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:17,代码来源:trie.go

示例10: BenchmarkRegister

func BenchmarkRegister(b *testing.B) {
	c := config.DefaultConfig()
	mbus := fakeyagnats.New()
	r := registry.NewRegistry(c, mbus)
	p := proxy.NewProxy(c, r, varz.NewVarz(r))

	for i := 0; i < b.N; i++ {
		str := strconv.Itoa(i)

		p.Register(
			route.Uri("bench.vcap.me."+str),
			&route.Endpoint{
				Host: "localhost",
				Port: uint16(i),
			},
		)
	}
}
开发者ID:nakaji-s,项目名称:gorouter,代码行数:18,代码来源:perf_test.go

示例11: refreshEndpoints

func (r *RouteFetcher) refreshEndpoints(validRoutes []db.Route) {
	r.deleteEndpoints(validRoutes)

	r.endpoints = validRoutes

	for _, aRoute := range r.endpoints {
		r.RouteRegistry.Register(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.TTL,
			))
	}
}
开发者ID:trainchou,项目名称:gorouter,代码行数:18,代码来源:route_fetcher.go

示例12: registerAddr

func (s *ProxySuite) registerAddr(u string, a net.Addr) {
	h, p, err := net.SplitHostPort(a.String())
	if err != nil {
		panic(err)
	}

	x, err := strconv.Atoi(p)
	if err != nil {
		panic(err)
	}

	s.r.Register(
		route.Uri(u),
		&route.Endpoint{
			Host: h,
			Port: uint16(x),
		},
	)
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:19,代码来源:proxy_test.go

示例13: refreshEndpoints

func (r *RouteFetcher) refreshEndpoints(validRoutes []models.Route) {
	r.deleteEndpoints(validRoutes)

	r.endpoints = validRoutes

	for _, aRoute := range r.endpoints {
		r.RouteRegistry.Register(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.GetTTL(),
				aRoute.RouteServiceUrl,
				aRoute.ModificationTag,
			))
	}
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:20,代码来源:route_fetcher.go

示例14: lookup

func (p *proxy) lookup(request *http.Request) *route.Pool {
	requestPath := request.URL.EscapedPath()

	uri := route.Uri(hostWithoutPort(request) + requestPath)
	return p.registry.Lookup(uri)
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:6,代码来源:proxy.go

示例15:

				conn.Close()
			})
		})
	})

	Context("when the endpoint is nil", func() {
		It("responds with a 502 BadGateway", func() {
			ln := registerHandler(r, "nil-endpoint", func(conn *test_util.HttpConn) {
				conn.CheckLine("GET / HTTP/1.1")
				resp := test_util.NewResponse(http.StatusOK)
				conn.WriteResponse(resp)
				conn.Close()
			})
			defer ln.Close()

			pool := r.Lookup(route.Uri("nil-endpoint"))
			endpoints := make([]*route.Endpoint, 0)
			pool.Each(func(e *route.Endpoint) {
				endpoints = append(endpoints, e)
			})
			for _, e := range endpoints {
				pool.Remove(e)
			}

			conn := dialProxy(proxyServer)

			req := test_util.NewRequest("GET", "nil-endpoint", "/", nil)
			conn.WriteRequest(req)

			b := make([]byte, 0, 0)
			buf := bytes.NewBuffer(b)
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:31,代码来源:proxy_test.go


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