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

Golang router.Store函数代码示例

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

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



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

示例1: TestSetCName

func (s *S) TestSetCName(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name:       "myapp",
		RootRuleId: "myrootrule",
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	s.handler.ConditionalContent = map[string]interface{}{
		"/api/virtualhost/": `{"_links":{"self":"vhX"}}`,
	}
	s.handler.RspCode = http.StatusCreated
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	err = gRouter.SetCName("my.new.cname", "myapp")
	c.Assert(err, check.IsNil)
	c.Assert(s.handler.Url, check.DeepEquals, []string{"/api/virtualhost/"})
	dbData, err := getGalebData("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(dbData.CNames, check.DeepEquals, []galebCNameData{
		{CName: "my.new.cname", VirtualHostId: "vhX"},
	})
	result := map[string]interface{}{}
	err = json.Unmarshal(s.handler.Body[0], &result)
	c.Assert(err, check.IsNil)
	c.Assert(result, check.DeepEquals, map[string]interface{}{
		"name": "my.new.cname", "farmtype": "", "plan": "", "environment": "", "project": "", "rule_default": "myrootrule",
	})
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:30,代码来源:router_test.go


示例2: TestAddRouteParsesURL

func (s *S) TestAddRouteParsesURL(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name:          "myapp",
		BackendPoolId: "mybackendpoolid",
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	s.handler.ConditionalContent = map[string]interface{}{
		"/api/backend/": `{"_links":{"self":"backend1"}}`,
	}
	s.handler.RspCode = http.StatusCreated
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	addr, _ := url.Parse("http://10.9.9.9:11001/")
	err = gRouter.AddRoute("myapp", addr)
	c.Assert(err, check.IsNil)
	c.Assert(s.handler.Url, check.DeepEquals, []string{"/api/backend/"})
	dbData, err := getGalebData("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(dbData.Reals, check.DeepEquals, []galebRealData{
		{Real: "10.9.9.9:11001", BackendId: "backend1"},
	})
	result := map[string]interface{}{}
	err = json.Unmarshal(s.handler.Body[0], &result)
	c.Assert(err, check.IsNil)
	c.Assert(result, check.DeepEquals, map[string]interface{}{
		"ip": "10.9.9.9", "port": float64(11001), "backendpool": "mybackendpoolid",
	})
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:31,代码来源:router_test.go


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


示例4: AddBackend

func (r elbRouter) AddBackend(name string) error {
	var err error
	options := elb.CreateLoadBalancer{
		Name: name,
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "HTTP",
				LoadBalancerPort: 80,
				Protocol:         "HTTP",
			},
		},
	}
	vpc, _ := config.GetBool("juju:elb-use-vpc")
	if vpc {
		options.Subnets, err = config.GetList("juju:elb-vpc-subnets")
		if err != nil {
			return err
		}
		options.SecurityGroups, err = config.GetList("juju:elb-vpc-secgroups")
		if err != nil {
			return err
		}
		options.Scheme = "internal"
	} else {
		options.AvailZones, err = config.GetList("juju:elb-avail-zones")
		if err != nil {
			return err
		}
	}
	_, err = r.elb().CreateLoadBalancer(&options)
	return router.Store(name, name)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:33,代码来源:router.go


示例5: AddBackend

func (r *fakeRouter) AddBackend(name string) error {
	if r.HasBackend(name) {
		return errors.New("Backend already exists")
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	r.backends[name] = nil
	return router.Store(name, name, "fake")
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:9,代码来源:router.go


示例6: AddBackend

func (r *fakeRouter) AddBackend(name string) error {
	if r.HasBackend(name) {
		return router.ErrBackendExists
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	r.backends[name] = nil
	return router.Store(name, name, "fake")
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:9,代码来源:router.go


示例7: TestAddr

func (s *S) TestAddr(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name: "myapp",
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	addr, err := gRouter.Addr("myapp")
	c.Assert(addr, check.Equals, "myapp.galeb.com")
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:13,代码来源:router_test.go


示例8: AddBackend

func (hipacheRouter) AddBackend(name string) error {
	domain, err := config.GetString("hipache:domain")
	if err != nil {
		return &routeError{"add", err}
	}
	frontend := "frontend:" + name + "." + domain
	conn := connect()
	defer conn.Close()
	_, err = conn.Do("RPUSH", frontend, name)
	if err != nil {
		return &routeError{"add", err}
	}
	return router.Store(name, name)
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:14,代码来源:router.go


示例9: addBackend

func (r *fusisRouter) addBackend(name string, proto string, port uint16) error {
	srv := fusisTypes.Service{
		Name:      name,
		Port:      port,
		Protocol:  proto,
		Scheduler: r.scheduler,
	}
	_, err := r.client.CreateService(srv)
	if err != nil {
		if err == fusisTypes.ErrServiceAlreadyExists {
			return router.ErrBackendExists
		}
		return err
	}
	return router.Store(name, name, routerType)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:16,代码来源:fusis.go


示例10: TestRoutes

func (s *S) TestRoutes(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name: "myapp",
		Reals: []galebRealData{
			{Real: "10.1.1.10", BackendId: s.server.URL + "/api/backend1"},
			{Real: "10.1.1.11", BackendId: s.server.URL + "/api/backend2"},
		},
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	routes, err := gRouter.Routes("myapp")
	c.Assert(err, check.IsNil)
	route1, _ := url.Parse("http://10.1.1.10")
	route2, _ := url.Parse("http://10.1.1.11")
	c.Assert(routes, check.DeepEquals, []*url.URL{route1, route2})
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:20,代码来源:router_test.go


示例11: AddBackend

func (r *hipacheRouter) AddBackend(name string) error {
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	frontend := "frontend:" + name + "." + domain
	conn := r.connect()
	defer conn.Close()
	exists, err := redis.Bool(conn.Do("EXISTS", frontend))
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	if exists {
		return router.ErrBackendExists
	}
	_, err = conn.Do("RPUSH", frontend, name)
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	return router.Store(name, name, routerName)
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:21,代码来源:router.go


示例12: TestUnsetCName

func (s *S) TestUnsetCName(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name: "myapp",
		CNames: []galebCNameData{
			{CName: "my.new.cname", VirtualHostId: s.server.URL + "/api/vh999"},
		},
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	s.handler.RspCode = http.StatusNoContent
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	err = gRouter.UnsetCName("my.new.cname", "myapp")
	c.Assert(err, check.IsNil)
	c.Assert(s.handler.Url, check.DeepEquals, []string{"/api/vh999"})
	dbData, err := getGalebData("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(dbData.CNames, check.DeepEquals, []galebCNameData{})
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:21,代码来源:router_test.go


示例13: AddBackend

func (r *galebRouter) AddBackend(name string) error {
	poolParams := galebClient.BackendPoolParams{
		Name: poolName(name),
	}
	_, err := getGalebData(name)
	if err == nil {
		return router.ErrBackendExists
	}
	data := galebData{Name: name}
	client, err := r.getClient()
	if err != nil {
		return err
	}
	data.BackendPoolId, err = client.AddBackendPool(&poolParams)
	if err != nil {
		return err
	}
	ruleParams := galebClient.RuleParams{
		Name:        rootRuleName(name),
		Match:       "/",
		BackendPool: data.BackendPoolId,
	}
	data.RootRuleId, err = client.AddRule(&ruleParams)
	if err != nil {
		return err
	}
	virtualHostParams := galebClient.VirtualHostParams{
		Name:        r.virtualHostName(name),
		RuleDefault: data.RootRuleId,
	}
	data.VirtualHostId, err = client.AddVirtualHost(&virtualHostParams)
	if err != nil {
		return err
	}
	err = data.save()
	if err != nil {
		return err
	}
	return router.Store(name, name, routerName)
}
开发者ID:4eek,项目名称:tsuru,代码行数:40,代码来源:router.go


示例14: TestRemoveRouteParsesURL

func (s *S) TestRemoveRouteParsesURL(c *check.C) {
	err := router.Store("myapp", "myapp", routerName)
	c.Assert(err, check.IsNil)
	data := galebData{
		Name: "myapp",
		Reals: []galebRealData{
			{Real: "10.1.1.10:1010", BackendId: s.server.URL + "/api/backend1"},
		},
	}
	err = data.save()
	c.Assert(err, check.IsNil)
	s.handler.RspCode = http.StatusNoContent
	gRouter, err := createRouter("routers:galeb")
	c.Assert(err, check.IsNil)
	addr, _ := url.Parse("https://10.1.1.10:1010/")
	err = gRouter.RemoveRoute("myapp", addr)
	c.Assert(err, check.IsNil)
	c.Assert(s.handler.Url, check.DeepEquals, []string{"/api/backend1"})
	dbData, err := getGalebData("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(dbData.Reals, check.DeepEquals, []galebRealData{})
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:22,代码来源:router_test.go


示例15: AddBackend

func (r *galebRouter) AddBackend(name string) error {
	backendPoolId, err := r.client.AddBackendPool(poolName(name))
	if err == galebClient.ErrItemAlreadyExists {
		return router.ErrBackendExists
	}
	if err != nil {
		return err
	}
	virtualHostId, err := r.client.AddVirtualHost(r.virtualHostName(name))
	if err != nil {
		return err
	}
	ruleId, err := r.client.AddRuleToID(ruleName(name), backendPoolId)
	if err != nil {
		return err
	}
	err = r.client.SetRuleVirtualHostIDs(ruleId, virtualHostId)
	if err != nil {
		return err
	}
	return router.Store(name, name, routerName)
}
开发者ID:hermancaldara,项目名称:tsuru,代码行数:22,代码来源:router.go


示例16: AddBackend

func (r *vulcandRouter) AddBackend(name string) error {
	backendName := r.backendName(name)
	frontendName := r.frontendName(r.frontendHostname(name))
	backendKey := engine.BackendKey{Id: backendName}
	frontendKey := engine.FrontendKey{Id: frontendName}
	if found, _ := r.client.GetBackend(backendKey); found != nil {
		return router.ErrBackendExists
	}
	if found, _ := r.client.GetFrontend(frontendKey); found != nil {
		return router.ErrBackendExists
	}
	backend, err := engine.NewHTTPBackend(
		backendName,
		engine.HTTPBackendSettings{},
	)
	if err != nil {
		return &router.RouterError{Err: err, Op: "add-backend"}
	}
	err = r.client.UpsertBackend(*backend)
	if err != nil {
		return err
	}
	frontend, err := engine.NewHTTPFrontend(
		route.NewMux(),
		frontendName,
		backend.Id,
		fmt.Sprintf(`Host(%q)`, r.frontendHostname(name)),
		engine.HTTPFrontendSettings{},
	)
	if err != nil {
		return &router.RouterError{Err: err, Op: "add-backend"}
	}
	err = r.client.UpsertFrontend(*frontend, engine.NoTTL)
	if err != nil {
		r.client.DeleteBackend(backendKey)
		return &router.RouterError{Err: err, Op: "add-backend"}
	}
	return router.Store(name, name, routerName)
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:39,代码来源:router.go


示例17: AddBackend

func (r *hipacheRouter) AddBackend(name string) error {
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	frontend := "frontend:" + name + "." + domain
	conn, err := r.connect()
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	exists, err := conn.Exists(frontend).Result()
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	if exists {
		return router.ErrBackendExists
	}
	err = conn.RPush(frontend, name).Err()
	if err != nil {
		return &router.RouterError{Op: "add", Err: err}
	}
	return router.Store(name, name, routerType)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:23,代码来源:router.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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