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

Golang router.Retrieve函数代码示例

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

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



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

示例1: RemoveRoute

func (r *fakeRouter) RemoveRoute(name string, address *url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if !r.HasBackend(backendName) {
		return router.ErrBackendNotFound
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	if r.failuresByIp[address.String()] {
		return ErrForcedFailure
	}
	index := -1
	routes := r.backends[backendName]
	for i := range routes {
		if routes[i] == address.String() {
			index = i
			break
		}
	}
	if index < 0 {
		return router.ErrRouteNotFound
	}
	routes[index] = routes[len(routes)-1]
	r.backends[backendName] = routes[:len(routes)-1]
	return nil
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:28,代码来源:router.go


示例2: TestSwap

func (s *ExternalSuite) TestSwap(c *check.C) {
	backend1 := "b1"
	backend2 := "b2"
	r, err := router.Get("fake")
	c.Assert(err, check.IsNil)
	r.AddBackend(backend1)
	addr1, _ := url.Parse("http://127.0.0.1")
	r.AddRoute(backend1, addr1)
	r.AddBackend(backend2)
	addr2, _ := url.Parse("http://10.10.10.10")
	r.AddRoute(backend2, addr2)
	err = router.Swap(r, backend1, backend2)
	c.Assert(err, check.IsNil)
	routes1, err := r.Routes(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(routes1, check.DeepEquals, []*url.URL{addr1})
	routes2, err := r.Routes(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(routes2, check.DeepEquals, []*url.URL{addr2})
	name1, err := router.Retrieve(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(name1, check.Equals, backend2)
	name2, err := router.Retrieve(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(name2, check.Equals, backend1)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:26,代码来源:router_swap_test.go


示例3: TestRemoveBackendKeepsInRouter

func (s *RouterSuite) TestRemoveBackendKeepsInRouter(c *check.C) {
	_, err := router.Retrieve(testBackend1)
	c.Assert(err, check.Equals, router.ErrBackendNotFound)
	err = s.Router.AddBackend(testBackend1)
	c.Assert(err, check.IsNil)
	name, err := router.Retrieve(testBackend1)
	c.Assert(err, check.IsNil)
	c.Assert(name, check.Equals, testBackend1)
	err = s.Router.RemoveBackend(testBackend1)
	c.Assert(err, check.IsNil)
	name, err = router.Retrieve(testBackend1)
	c.Assert(err, check.IsNil)
	c.Assert(name, check.Equals, testBackend1)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:14,代码来源:generic_suite.go


示例4: TestSwapCnameOnly

func (s *ExternalSuite) TestSwapCnameOnly(c *check.C) {
	backend1 := "bx1"
	backend2 := "bx2"
	r, err := router.Get("fake")
	c.Assert(err, check.IsNil)
	cnameRouter, ok := r.(router.CNameRouter)
	c.Assert(ok, check.Equals, true)
	err = r.AddBackend(backend1)
	c.Assert(err, check.IsNil)
	addr1, err := url.Parse("http://127.0.0.1")
	c.Assert(err, check.IsNil)
	r.AddRoute(backend1, addr1)
	err = cnameRouter.SetCName("cname.com", backend1)
	c.Assert(err, check.IsNil)
	err = r.AddBackend(backend2)
	c.Assert(err, check.IsNil)
	addr2, err := url.Parse("http://10.10.10.10")
	c.Assert(err, check.IsNil)
	r.AddRoute(backend2, addr2)
	err = router.Swap(r, backend1, backend2, true)
	c.Assert(err, check.IsNil)
	routes1, err := r.Routes(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(routes1, check.DeepEquals, []*url.URL{addr1})
	routes2, err := r.Routes(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(routes2, check.DeepEquals, []*url.URL{addr2})
	name1, err := router.Retrieve(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(name1, check.Equals, backend1)
	name2, err := router.Retrieve(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(name2, check.Equals, backend2)
	cnames, err := cnameRouter.CNames(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(cnames, check.HasLen, 0)
	expected := []*url.URL{{Host: "cname.com"}}
	cnames, err = cnameRouter.CNames(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(expected, check.DeepEquals, cnames)
	err = router.Swap(r, backend1, backend2, true)
	c.Assert(err, check.IsNil)
	cnames, err = cnameRouter.CNames(backend1)
	c.Assert(err, check.IsNil)
	c.Assert(expected, check.DeepEquals, cnames)
	cnames, err = cnameRouter.CNames(backend2)
	c.Assert(err, check.IsNil)
	c.Assert(cnames, check.HasLen, 0)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:49,代码来源:router_swap_test.go


示例5: RemoveRoutes

func (r *fakeRouter) RemoveRoutes(name string, addresses []*url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if !r.HasBackend(backendName) {
		return router.ErrBackendNotFound
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	for _, addr := range addresses {
		if r.failuresByIp[addr.Host] {
			return ErrForcedFailure
		}
	}
	routes := r.backends[backendName]
	for _, addr := range addresses {
		for i := range routes {
			if routes[i] == addr.Host {
				routes = append(routes[:i], routes[i+1:]...)
				break
			}
		}
	}
	r.backends[backendName] = routes
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:27,代码来源:router.go


示例6: TestRemoveBackend

func (s *S) TestRemoveBackend(c *check.C) {
	s.handler.RspCode = http.StatusNoContent
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name:          "myapp",
		BackendPoolId: s.server.URL + "/api/backend1",
		RootRuleId:    s.server.URL + "/api/rule1",
		VirtualHostId: s.server.URL + "/api/vh1",
		CNames: []galebCNameData{
			{CName: "my.1.cname", VirtualHostId: s.server.URL + "/api/vh2"},
			{CName: "my.2.cname", VirtualHostId: s.server.URL + "/api/vh3"},
		},
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	err = gRouter.RemoveBackend("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(s.handler.Url, check.DeepEquals, []string{
		"/api/vh1", "/api/vh2", "/api/vh3", "/api/rule1", "/api/backend1",
	})
	_, err = router.Retrieve("myapp")
	c.Assert(err, check.Equals, router.ErrBackendNotFound)
	_, err = getGalebData("myapp")
	c.Assert(err, check.ErrorMatches, "not found")
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:28,代码来源:router_test.go


示例7: RemoveRoute

func (r *fakeRouter) RemoveRoute(name, ip string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if !r.HasBackend(backendName) {
		return ErrBackendNotFound
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	index := -1
	routes := r.backends[backendName]
	for i := range routes {
		if routes[i] == ip {
			index = i
			break
		}
	}
	if index < 0 {
		return errors.New("Route not found")
	}
	routes[index] = routes[len(routes)-1]
	r.backends[backendName] = routes[:len(routes)-1]
	return nil
}
开发者ID:ningjh,项目名称:tsuru,代码行数:25,代码来源:router.go


示例8: SetCName

func (r *galebRouter) SetCName(cname, name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return err
	}
	if !router.ValidCName(cname, domain) {
		return router.ErrCNameNotAllowed
	}
	data, err := getGalebData(backendName)
	if err != nil {
		return err
	}
	client, err := r.getClient()
	if err != nil {
		return err
	}
	for _, val := range data.CNames {
		if val.CName == cname {
			return router.ErrCNameExists
		}
	}
	virtualHostParams := galebClient.VirtualHostParams{
		Name:        cname,
		RuleDefault: data.RootRuleId,
	}
	virtualHostId, err := client.AddVirtualHost(&virtualHostParams)
	if err != nil {
		return err
	}
	return data.addCName(cname, virtualHostId)
}
开发者ID:4eek,项目名称:tsuru,代码行数:35,代码来源:router.go


示例9: Routes

func (r *hipacheRouter) Routes(name string) ([]*url.URL, error) {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return nil, err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return nil, &router.RouterError{Op: "routes", Err: err}
	}
	frontend := "frontend:" + backendName + "." + domain
	conn := r.connect()
	defer conn.Close()
	routes, err := redis.Strings(conn.Do("LRANGE", frontend, 1, -1))
	if err != nil {
		return nil, &router.RouterError{Op: "routes", Err: err}
	}
	result := make([]*url.URL, len(routes))
	for i, route := range routes {
		result[i], err = url.Parse(route)
		if err != nil {
			return nil, err
		}
	}
	return result, nil
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:25,代码来源:router.go


示例10: SetCName

func (r *vulcandRouter) SetCName(cname, name string) error {
	usedName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if !router.ValidCName(cname, r.domain) {
		return router.ErrCNameNotAllowed
	}
	frontendName := r.frontendName(cname)
	if found, _ := r.client.GetFrontend(engine.FrontendKey{Id: frontendName}); found != nil {
		return router.ErrCNameExists
	}
	frontend, err := engine.NewHTTPFrontend(
		frontendName,
		r.backendName(usedName),
		fmt.Sprintf(`Host(%q)`, cname),
		engine.HTTPFrontendSettings{},
	)
	if err != nil {
		return &router.RouterError{Err: err, Op: "set-cname"}
	}
	err = r.client.UpsertFrontend(*frontend, engine.NoTTL)
	if err != nil {
		return &router.RouterError{Err: err, Op: "set-cname"}
	}
	return nil
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:27,代码来源:router.go


示例11: SetCName

func (r *hipacheRouter) SetCName(cname, name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &routeError{"setCName", err}
	}
	if !r.validCName(cname) {
		err := errors.New(fmt.Sprintf("Invalid CNAME %s. You can't use tsuru's application domain.", cname))
		return &routeError{"setCName", err}
	}
	frontend := "frontend:" + backendName + "." + domain
	conn := r.connect()
	defer conn.Close()
	routes, err := redis.Strings(conn.Do("LRANGE", frontend, 0, -1))
	if err != nil {
		return &routeError{"get", err}
	}
	_, err = conn.Do("RPUSH", "cname:"+backendName, cname)
	if err != nil {
		return &routeError{"set", err}
	}
	frontend = "frontend:" + cname
	for _, r := range routes {
		_, err := conn.Do("RPUSH", frontend, r)
		if err != nil {
			return &routeError{"setCName", err}
		}
	}
	return nil
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:33,代码来源:router.go


示例12: RemoveRoute

func (r *hipacheRouter) RemoveRoute(name string, address *url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &routeError{"remove", err}
	}
	frontend := "frontend:" + backendName + "." + domain
	if err := r.removeElement(frontend, address.String()); err != nil {
		return err
	}
	cnames, err := r.getCNames(backendName)
	if err != nil {
		return &routeError{"remove", err}
	}
	if cnames == nil {
		return nil
	}
	for _, cname := range cnames {
		err = r.removeElement("frontend:"+cname, address.String())
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:28,代码来源:router.go


示例13: AddRoute

func (r *hipacheRouter) AddRoute(name string, address *url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		log.Errorf("error on getting hipache domain in add route for %s - %s", backendName, address)
		return &routeError{"add", err}
	}
	frontend := "frontend:" + backendName + "." + domain
	if err := r.addRoute(frontend, address.String()); err != nil {
		log.Errorf("error on add route for %s - %s", backendName, address)
		return &routeError{"add", err}
	}
	cnames, err := r.getCNames(backendName)
	if err != nil {
		log.Errorf("error on get cname in add route for %s - %s", backendName, address)
		return err
	}
	if cnames == nil {
		return nil
	}
	for _, cname := range cnames {
		err = r.addRoute("frontend:"+cname, address.String())
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:31,代码来源:router.go


示例14: AddRoutes

func (r *galebRouter) AddRoutes(name string, addresses []*url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	return r.client.AddBackends(addresses, r.poolName(backendName))
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:7,代码来源:router.go


示例15: AddRoute

func (r *galebRouter) AddRoute(name string, address *url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	data, err := getGalebData(backendName)
	if err != nil {
		return err
	}
	for _, r := range data.Reals {
		if r.Real == address.Host {
			return router.ErrRouteExists
		}
	}
	client, err := r.getClient()
	if err != nil {
		return err
	}
	host, portStr, _ := net.SplitHostPort(address.Host)
	port, _ := strconv.Atoi(portStr)
	params := galebClient.BackendParams{
		Ip:          host,
		Port:        port,
		BackendPool: data.BackendPoolId,
	}
	backendId, err := client.AddBackend(&params)
	if err != nil {
		return err
	}
	return data.addReal(address.Host, backendId)
}
开发者ID:4eek,项目名称:tsuru,代码行数:31,代码来源:router.go


示例16: UnsetCName

func (r *hipacheRouter) UnsetCName(cname, name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	conn := r.connect()
	defer conn.Close()
	currentCnames, err := redis.Strings(conn.Do("LRANGE", "cname:"+backendName, 0, -1))
	found := false
	for _, n := range currentCnames {
		if n == cname {
			found = true
			break
		}
	}
	if !found {
		return router.ErrCNameNotFound
	}
	_, err = conn.Do("LREM", "cname:"+backendName, 0, cname)
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	_, err = conn.Do("DEL", "frontend:"+cname)
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	return nil
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:28,代码来源:router.go


示例17: Addr

func (r *galebRouter) Addr(name string) (string, error) {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return "", err
	}
	return r.virtualHostName(backendName), nil
}
开发者ID:hermancaldara,项目名称:tsuru,代码行数:7,代码来源:router.go


示例18: Routes

func (r *hipacheRouter) Routes(name string) ([]*url.URL, error) {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return nil, err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return nil, &router.RouterError{Op: "routes", Err: err}
	}
	frontend := "frontend:" + backendName + "." + domain
	conn, err := r.connect()
	if err != nil {
		return nil, &router.RouterError{Op: "routes", Err: err}
	}
	routes, err := conn.LRange(frontend, 0, -1).Result()
	if err != nil {
		return nil, &router.RouterError{Op: "routes", Err: err}
	}
	if len(routes) == 0 {
		return nil, router.ErrBackendNotFound
	}
	routes = routes[1:]
	result := make([]*url.URL, len(routes))
	for i, route := range routes {
		result[i], err = url.Parse(route)
		if err != nil {
			return nil, err
		}
	}
	return result, nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:31,代码来源:router.go


示例19: UnsetCName

func (r *hipacheRouter) UnsetCName(cname, name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	conn, err := r.connect()
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	currentCnames, err := conn.LRange("cname:"+backendName, 0, -1).Result()
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	found := false
	for _, n := range currentCnames {
		if n == cname {
			found = true
			break
		}
	}
	if !found {
		return router.ErrCNameNotFound
	}
	err = conn.LRem("cname:"+backendName, 0, cname).Err()
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	err = conn.Del("frontend:" + cname).Err()
	if err != nil {
		return &router.RouterError{Op: "unsetCName", Err: err}
	}
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:33,代码来源:router.go


示例20: RemoveRoute

func (r *hipacheRouter) RemoveRoute(name string, address *url.URL) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	frontend := "frontend:" + backendName + "." + domain
	address.Scheme = router.HttpScheme
	count, err := r.removeElement(frontend, address.String())
	if err != nil {
		return err
	}
	if count == 0 {
		return router.ErrRouteNotFound
	}
	cnames, err := r.getCNames(backendName)
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	if cnames == nil {
		return nil
	}
	for _, cname := range cnames {
		_, err = r.removeElement("frontend:"+cname, address.String())
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:33,代码来源:router.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang router.Store函数代码示例发布时间:2022-05-28
下一篇:
Golang router.Remove函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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