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


Golang router.Get函数代码示例

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


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

func (s *S) TestShouldBeRegisteredAllowingPrefixes(c *check.C) {
	config.Set("routers:inst1:type", "vulcand")
	config.Set("routers:inst1:api-url", "http://localhost:1")
	config.Set("routers:inst1:domain", "inst1.example.com")
	config.Set("routers:inst2:type", "vulcand")
	config.Set("routers:inst2:api-url", "http://localhost:2")
	config.Set("routers:inst2:domain", "inst2.example.com")
	defer config.Unset("routers:inst1:type")
	defer config.Unset("routers:inst1:api-url")
	defer config.Unset("routers:inst1:domain")
	defer config.Unset("routers:inst2:type")
	defer config.Unset("routers:inst2:api-url")
	defer config.Unset("routers:inst2:domain")
	got1, err := router.Get("inst1")
	c.Assert(err, check.IsNil)
	got2, err := router.Get("inst2")
	c.Assert(err, check.IsNil)
	r1, ok := got1.(*vulcandRouter)
	c.Assert(ok, check.Equals, true)
	c.Assert(r1.client.Addr, check.Equals, "http://localhost:1")
	c.Assert(r1.domain, check.Equals, "inst1.example.com")
	c.Assert(r1.prefix, check.Equals, "routers:inst1")
	r2, ok := got2.(*vulcandRouter)
	c.Assert(ok, check.Equals, true)
	c.Assert(r2.client.Addr, check.Equals, "http://localhost:2")
	c.Assert(r2.domain, check.Equals, "inst2.example.com")
	c.Assert(r2.prefix, check.Equals, "routers:inst2")
}
开发者ID:reoring,项目名称:tsuru,代码行数:28,代码来源:router_test.go

示例3: TestShouldBeRegistered

func (s *S) TestShouldBeRegistered(c *check.C) {
	r, err := router.Get("fake")
	c.Assert(err, check.IsNil)
	c.Assert(r, check.FitsTypeOf, &fakeRouter{})
	r, err = router.Get("fake-hc")
	c.Assert(err, check.IsNil)
	c.Assert(r, check.FitsTypeOf, &hcRouter{})
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:8,代码来源:router_test.go

示例4: Router

func (app *App) Router() (router.Router, error) {
	routerName, err := app.GetRouter()
	if err != nil {
		return nil, err
	}
	return router.Get(routerName)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:7,代码来源:app.go

示例5: Example

func Example() {
	router, err := router.Get("hipache")
	if err != nil {
		panic(err)
	}
	err = router.AddBackend("myapp")
	if err != nil {
		panic(err)
	}
	url, err := url.Parse("http://10.10.10.10:8080")
	if err != nil {
		panic(err)
	}
	err = router.AddRoute("myapp", url)
	if err != nil {
		panic(err)
	}
	addr, _ := router.Addr("myapp")
	fmt.Println("Please access:", addr)
	err = router.RemoveRoute("myapp", url)
	if err != nil {
		panic(err)
	}
	err = router.RemoveBackend("myapp")
	if err != nil {
		panic(err)
	}
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:28,代码来源:example_test.go

示例6: TestShouldBeRegisteredAllowingPrefixes

func (s *S) TestShouldBeRegisteredAllowingPrefixes(c *check.C) {
	config.Set("routers:inst1:type", "hipache")
	config.Set("routers:inst2:type", "hipache")
	defer config.Unset("routers:inst1:type")
	defer config.Unset("routers:inst2:type")
	got1, err := router.Get("inst1")
	c.Assert(err, check.IsNil)
	got2, err := router.Get("inst2")
	c.Assert(err, check.IsNil)
	r1, ok := got1.(*hipacheRouter)
	c.Assert(ok, check.Equals, true)
	c.Assert(r1.prefix, check.Equals, "routers:inst1")
	r2, ok := got2.(*hipacheRouter)
	c.Assert(ok, check.Equals, true)
	c.Assert(r2.prefix, check.Equals, "routers:inst2")
}
开发者ID:ggarnier,项目名称:tsuru,代码行数:16,代码来源:router_test.go

示例7: getRouterForApp

func getRouterForApp(app provision.App) (router.Router, error) {
	routerName, err := app.GetRouter()
	if err != nil {
		return nil, err
	}
	return router.Get(routerName)
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:7,代码来源:provisioner.go

示例8: Save

func (plan *Plan) Save() error {
	if plan.Name == "" {
		return PlanValidationError{"name"}
	}
	if plan.CpuShare < 2 {
		return ErrLimitOfCpuShare
	}
	if plan.Memory > 0 && plan.Memory < 4194304 {
		return ErrLimitOfMemory
	}
	if plan.Router != "" {
		_, err := router.Get(plan.Router)
		if err != nil {
			return PlanValidationError{fmt.Sprintf("router error: %v", err)}
		}
	}
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	if plan.Default {
		_, err = conn.Plans().UpdateAll(bson.M{"default": true}, bson.M{"$unset": bson.M{"default": false}})
		if err != nil {
			return err
		}
	}
	err = conn.Plans().Insert(plan)
	if err != nil && strings.Contains(err.Error(), "duplicate key") {
		return ErrPlanAlreadyExists
	}
	return err
}
开发者ID:tsuru,项目名称:tsuru,代码行数:33,代码来源:plan.go

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

示例10: Save

func (plan *Plan) Save() error {
	if plan.Name == "" {
		return PlanValidationError{"name"}
	}
	if plan.CpuShare == 0 {
		return PlanValidationError{"cpushare"}
	}
	if plan.Router != "" {
		_, err := router.Get(plan.Router)
		if err != nil {
			return PlanValidationError{"router"}
		}
	}
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	if plan.Default {
		_, err := conn.Plans().UpdateAll(bson.M{"default": true}, bson.M{"$unset": bson.M{"default": false}})
		if err != nil {
			return err
		}
	}
	err = conn.Plans().Insert(plan)
	if err != nil && strings.Contains(err.Error(), "duplicate key") {
		return ErrPlanAlreadyExists
	}
	return err
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:30,代码来源:plan.go

示例11: TestSetCName

func (s *S) TestSetCName(c *check.C) {
	vRouter, err := router.Get("vulcand")
	c.Assert(err, check.IsNil)
	err = vRouter.AddBackend("myapp")
	c.Assert(err, check.IsNil)
	u1, _ := url.Parse("http://1.1.1.1:111")
	u2, _ := url.Parse("http://2.2.2.2:222")
	err = vRouter.AddRoute("myapp", u1)
	c.Assert(err, check.IsNil)
	err = vRouter.AddRoute("myapp", u2)
	c.Assert(err, check.IsNil)
	err = vRouter.SetCName("myapp.cname.example.com", "myapp")
	c.Assert(err, check.IsNil)
	appFrontend, err := s.engine.GetFrontend(engine.FrontendKey{
		Id: "tsuru_myapp.vulcand.example.com",
	})
	c.Assert(err, check.IsNil)
	cnameFrontend, err := s.engine.GetFrontend(engine.FrontendKey{
		Id: "tsuru_myapp.cname.example.com",
	})
	c.Assert(err, check.IsNil)
	c.Assert(cnameFrontend.BackendId, check.DeepEquals, appFrontend.BackendId)
	c.Assert(cnameFrontend.Route, check.Equals, `Host("myapp.cname.example.com")`)
	c.Assert(cnameFrontend.Type, check.Equals, "http")
}
开发者ID:reoring,项目名称:tsuru,代码行数:25,代码来源:router_test.go

示例12: TestAddBackendRollbackOnError

func (s *S) TestAddBackendRollbackOnError(c *check.C) {
	s.vulcandServer.Close()
	scrollApp := scroll.NewApp()
	var postRequestCount int
	conditionalHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "POST" {
			postRequestCount++
			if postRequestCount > 1 {
				w.WriteHeader(http.StatusInternalServerError)
				return
			}
		}
		scrollApp.GetHandler().ServeHTTP(w, r)
	})
	api.InitProxyController(s.engine, &supervisor.Supervisor{}, scrollApp)
	s.vulcandServer = httptest.NewServer(conditionalHandler)
	config.Set("routers:vulcand:api-url", s.vulcandServer.URL)
	vRouter, err := router.Get("vulcand")
	c.Assert(err, check.IsNil)
	err = vRouter.AddBackend("myapp")
	c.Assert(err, check.NotNil)
	backends, err := s.engine.GetBackends()
	c.Assert(err, check.IsNil)
	c.Assert(backends, check.HasLen, 0)
	frontends, err := s.engine.GetFrontends()
	c.Assert(err, check.IsNil)
	c.Assert(frontends, check.HasLen, 0)
}
开发者ID:reoring,项目名称:tsuru,代码行数:28,代码来源:router_test.go

示例13: getRouter

func getRouter() (router.Router, error) {
	r, err := config.GetString("docker:router")
	if err != nil {
		return nil, err
	}
	return router.Get(r)
}
开发者ID:philiptzou,项目名称:tsuru,代码行数:7,代码来源:provisioner.go

示例14: TestHealthCheck

func (s *S) TestHealthCheck(c *check.C) {
	got, err := router.Get("vulcand")
	c.Assert(err, check.IsNil)
	hcRouter, ok := got.(router.HealthChecker)
	c.Assert(ok, check.Equals, true)
	c.Assert(hcRouter.HealthCheck(), check.IsNil)
}
开发者ID:reoring,项目名称:tsuru,代码行数:7,代码来源:router_test.go

示例15: TestShouldBeRegistered

func (s *S) TestShouldBeRegistered(c *check.C) {
	got, err := router.Get("vulcand")
	c.Assert(err, check.IsNil)
	r, ok := got.(*vulcandRouter)
	c.Assert(ok, check.Equals, true)
	c.Assert(r.client.Addr, check.Equals, s.vulcandServer.URL)
	c.Assert(r.domain, check.Equals, "vulcand.example.com")
}
开发者ID:reoring,项目名称:tsuru,代码行数:8,代码来源:router_test.go


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