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

Golang router.Swap函数代码示例

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

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



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

示例1: TestSwapWithDifferentRouterKinds

func (s *ExternalSuite) TestSwapWithDifferentRouterKinds(c *check.C) {
	config.Set("hipache:redis-server", "127.0.0.1:6379")
	config.Set("hipache:redis-db", 5)
	backend1 := "bb1"
	backend2 := "bb2"
	r1, err := router.Get("fake")
	c.Assert(err, check.IsNil)
	r2, err := router.Get("hipache")
	c.Assert(err, check.IsNil)
	err = r1.AddBackend(backend1)
	c.Assert(err, check.IsNil)
	defer r1.RemoveBackend(backend1)
	addr1, _ := url.Parse("http://127.0.0.1")
	err = r1.AddRoute(backend1, addr1)
	c.Assert(err, check.IsNil)
	defer r1.RemoveRoute(backend1, addr1)
	err = r2.AddBackend(backend2)
	c.Assert(err, check.IsNil)
	defer r2.RemoveBackend(backend2)
	addr2, _ := url.Parse("http://10.10.10.10")
	err = r2.AddRoute(backend2, addr2)
	c.Assert(err, check.IsNil)
	defer r2.RemoveRoute(backend2, addr2)
	err = router.Swap(r1, backend1, backend2, false)
	c.Assert(err, check.ErrorMatches, `swap is only allowed between routers of the same kind. "bb1" uses "fake", "bb2" uses "hipache"`)
	err = router.Swap(r2, backend1, backend2, false)
	c.Assert(err, check.ErrorMatches, `swap is only allowed between routers of the same kind. "bb1" uses "fake", "bb2" uses "hipache"`)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:28,代码来源:router_swap_test.go


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


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


示例4: TestSwapWithDifferentRouterKinds

func (s *ExternalSuite) TestSwapWithDifferentRouterKinds(c *check.C) {
	backend1 := "bb1"
	backend2 := "bb2"
	r1, err := router.Get("fake")
	c.Assert(err, check.IsNil)
	r2, err := router.Get("hipache")
	c.Assert(err, check.IsNil)
	err = r1.AddBackend(backend1)
	c.Assert(err, check.IsNil)
	addr1, _ := url.Parse("http://127.0.0.1")
	err = r1.AddRoute(backend1, addr1)
	c.Assert(err, check.IsNil)
	err = r2.AddBackend(backend2)
	c.Assert(err, check.IsNil)
	addr2, _ := url.Parse("http://10.10.10.10")
	err = r2.AddRoute(backend2, addr2)
	c.Assert(err, check.IsNil)
	err = router.Swap(r1, backend1, backend2)
	c.Assert(err, check.ErrorMatches, `swap is only allowed between routers of the same kind. "bb1" uses "fake", "bb2" uses "hipache"`)
	err = router.Swap(r2, backend1, backend2)
	c.Assert(err, check.ErrorMatches, `swap is only allowed between routers of the same kind. "bb1" uses "fake", "bb2" uses "hipache"`)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:22,代码来源:router_swap_test.go


示例5: Swap

func (r *galebRouter) Swap(backend1, backend2 string) error {
	return router.Swap(r, backend1, backend2)
}
开发者ID:hermancaldara,项目名称:tsuru,代码行数:3,代码来源:router.go


示例6: Swap

func (r *fusisRouter) Swap(backend1 string, backend2 string, cnameOnly bool) error {
	return router.Swap(r, backend1, backend2, cnameOnly)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:3,代码来源:fusis.go


示例7: Swap

func (r *hipacheRouter) Swap(backend1, backend2 string, cnameOnly bool) error {
	return router.Swap(r, backend1, backend2, cnameOnly)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:3,代码来源:router.go


示例8: Swap

func (r hipacheRouter) Swap(backend1, backend2 string) error {
	return router.Swap(r, backend1, backend2)
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:3,代码来源:router.go


示例9: Swap

func (r *vulcandRouter) Swap(backend1, backend2 string) error {
	return router.Swap(r, backend1, backend2)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:3,代码来源:router.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang router.ValidCName函数代码示例发布时间:2022-05-28
下一篇:
Golang router.Store函数代码示例发布时间: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