當前位置: 首頁>>代碼示例>>Golang>>正文


Golang router.Store函數代碼示例

本文整理匯總了Golang中github.com/tsuru/tsuru/router.Store函數的典型用法代碼示例。如果您正苦於以下問題:Golang Store函數的具體用法?Golang Store怎麽用?Golang Store使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Store函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/tsuru/tsuru/router.Store函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。