本文整理汇总了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"`)
}
示例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")
}
示例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{})
}
示例4: Router
func (app *App) Router() (router.Router, error) {
routerName, err := app.GetRouter()
if err != nil {
return nil, err
}
return router.Get(routerName)
}
示例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)
}
}
示例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")
}
示例7: getRouterForApp
func getRouterForApp(app provision.App) (router.Router, error) {
routerName, err := app.GetRouter()
if err != nil {
return nil, err
}
return router.Get(routerName)
}
示例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
}
示例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)
}
示例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
}
示例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")
}
示例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)
}
示例13: getRouter
func getRouter() (router.Router, error) {
r, err := config.GetString("docker:router")
if err != nil {
return nil, err
}
return router.Get(r)
}
示例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)
}
示例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")
}