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

Golang quota.Delete函数代码示例

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

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



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

示例1: TestCreateAppQuotaBackward

func (s *S) TestCreateAppQuotaBackward(c *gocheck.C) {
	app := App{
		Name:     "damned",
		Platform: "django",
	}
	err := quota.Create(app.Name, 1)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(app.Name)
	createAppQuota.Backward(action.BWContext{FWResult: app.Name})
	err = quota.Reserve(app.Name, "something")
	c.Assert(err, gocheck.Equals, quota.ErrQuotaNotFound)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:12,代码来源:actions_test.go


示例2: TestCreateAppQuotaForwardPointer

func (s *S) TestCreateAppQuotaForwardPointer(c *gocheck.C) {
	config.Set("quota:units-per-app", 2)
	defer config.Unset("quota:units-per-app")
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	defer quota.Delete(app.Name)
	previous, err := createAppQuota.Forward(action.FWContext{Params: []interface{}{&app}})
	c.Assert(err, gocheck.IsNil)
	c.Assert(previous, gocheck.Equals, app.Name)
	err = quota.Reserve(app.Name, "visions/0")
	c.Assert(err, gocheck.IsNil)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:14,代码来源:actions_test.go


示例3: removeUser

// removeUser removes the user from the database and from gandalf server
//
// If the user is the only one in a team an error will be returned.
func removeUser(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
	u, err := t.User()
	if err != nil {
		return err
	}
	gURL := repository.ServerURL()
	c := gandalf.Client{Endpoint: gURL}
	alwdApps, err := u.AllowedApps()
	if err != nil {
		return err
	}
	if err := c.RevokeAccess(alwdApps, []string{u.Email}); err != nil {
		log.Printf("Failed to revoke access in Gandalf: %s", err)
		return fmt.Errorf("Failed to revoke acess from git repositories: %s", err)
	}
	teams, err := u.Teams()
	if err != nil {
		return err
	}
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	for _, team := range teams {
		if len(team.Users) < 2 {
			msg := fmt.Sprintf(`This user is the last member of the team "%s", so it cannot be removed.

Please remove the team, them remove the user.`, team.Name)
			return &errors.HTTP{Code: http.StatusForbidden, Message: msg}
		}
		err = team.RemoveUser(u)
		if err != nil {
			return err
		}
		// this can be done without the loop
		err = conn.Teams().Update(bson.M{"_id": team.Name}, team)
		if err != nil {
			return err
		}
	}
	rec.Log(u.Email, "remove-user")
	if err := c.RemoveUser(u.Email); err != nil {
		log.Printf("Failed to remove user from gandalf: %s", err)
		return fmt.Errorf("Failed to remove the user from the git server: %s", err)
	}
	quota.Delete(u.Email)
	return conn.Users().Remove(bson.M{"email": u.Email})
}
开发者ID:pombredanne,项目名称:docker-stuff,代码行数:52,代码来源:auth.go


示例4: TestReserveUserAppForwardQuotaExceeded

func (s *S) TestReserveUserAppForwardQuotaExceeded(c *gocheck.C) {
	user := auth.User{Email: "[email protected]"}
	err := quota.Create(user.Email, 1)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(user.Email)
	err = quota.Reserve(user.Email, "anything")
	c.Assert(err, gocheck.IsNil)
	app := App{
		Name:     "clap",
		Platform: "django",
	}
	previous, err := reserveUserApp.Forward(action.FWContext{Params: []interface{}{app, user}})
	c.Assert(previous, gocheck.IsNil)
	_, ok := err.(*quota.QuotaExceededError)
	c.Assert(ok, gocheck.Equals, true)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:16,代码来源:actions_test.go


示例5: TestReserveUnitsToAddBackwardNoPointer

func (s *S) TestReserveUnitsToAddBackwardNoPointer(c *gocheck.C) {
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	err := quota.Create(app.Name, 5)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(app.Name)
	ids := []string{"visions-0", "visions-1", "visions-2", "visions-3"}
	err = quota.Reserve(app.Name, ids...)
	c.Assert(err, gocheck.IsNil)
	reserveUnitsToAdd.Backward(action.BWContext{Params: []interface{}{app, 3}, FWResult: ids})
	items, avail, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(avail, gocheck.Equals, uint(5))
	c.Assert(items, gocheck.HasLen, 0)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:17,代码来源:actions_test.go


示例6: TestChangeQuota

func (QuotaSuite) TestChangeQuota(c *gocheck.C) {
	err := quota.Create("[email protected]", 3)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete("[email protected]")
	recorder := httptest.NewRecorder()
	request, err := http.NewRequest("PUT", "/quota/[email protected]?:[email protected]m", strings.NewReader("quota=1"))
	c.Assert(err, gocheck.IsNil)
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	err = changeQuota(recorder, request, nil)
	c.Assert(err, gocheck.IsNil)
	_, qtd, err := quota.Items("[email protected]")
	c.Assert(err, gocheck.IsNil)
	c.Assert(int(qtd), gocheck.Equals, 1)
	c.Assert(recorder.Code, gocheck.Equals, http.StatusOK)
	body, err := ioutil.ReadAll(recorder.Body)
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(body), gocheck.Equals, "Quota changed sucessfully.")
}
开发者ID:nemx,项目名称:tsuru,代码行数:18,代码来源:quota_test.go


示例7: TestReserveUnitsToAddForwardNoPointer

func (s *S) TestReserveUnitsToAddForwardNoPointer(c *gocheck.C) {
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	s.conn.Apps().Insert(app)
	defer s.conn.Apps().Remove(bson.M{"name": app.Name})
	err := quota.Create(app.Name, 5)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(app.Name)
	result, err := reserveUnitsToAdd.Forward(action.FWContext{Params: []interface{}{app, 3}})
	c.Assert(err, gocheck.IsNil)
	ids, ok := result.([]string)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(ids, gocheck.DeepEquals, []string{"visions-0", "visions-1", "visions-2"})
	items, avail, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(avail, gocheck.Equals, uint(2))
	c.Assert(items, gocheck.DeepEquals, []string{"visions-0", "visions-1", "visions-2"})
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:20,代码来源:actions_test.go


示例8: TestQuotaByOwner

func (QuotaSuite) TestQuotaByOwner(c *gocheck.C) {
	err := quota.Create("[email protected]", 3)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete("[email protected]")
	err = quota.Reserve("[email protected]", "tank/1")
	c.Assert(err, gocheck.IsNil)
	recorder := httptest.NewRecorder()
	request, err := http.NewRequest("GET", "/quota/[email protected]?:[email protected]", nil)
	c.Assert(err, gocheck.IsNil)
	err = quotaByOwner(recorder, request, nil)
	c.Assert(err, gocheck.IsNil)
	c.Assert(recorder.Code, gocheck.Equals, http.StatusOK)
	body, err := ioutil.ReadAll(recorder.Body)
	c.Assert(err, gocheck.IsNil)
	result := map[string]interface{}{}
	err = json.Unmarshal(body, &result)
	c.Assert(err, gocheck.IsNil)
	c.Assert(result["available"], gocheck.Equals, float64(2))
	c.Assert(result["items"], gocheck.DeepEquals, []interface{}{"tank/1"})
}
开发者ID:nemx,项目名称:tsuru,代码行数:20,代码来源:quota_test.go


示例9: TestCreateAppQuotaForward

func (s *S) TestCreateAppQuotaForward(c *gocheck.C) {
	config.Set("quota:units-per-app", 2)
	defer config.Unset("quota:units-per-app")
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	defer quota.Delete(app.Name)
	previous, err := createAppQuota.Forward(action.FWContext{Params: []interface{}{app}})
	c.Assert(err, gocheck.IsNil)
	c.Assert(previous, gocheck.Equals, app.Name)
	items, available, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(items, gocheck.DeepEquals, []string{"visions-0"})
	c.Assert(available, gocheck.Equals, uint(1))
	err = quota.Reserve(app.Name, "visions-1")
	c.Assert(err, gocheck.IsNil)
	err = quota.Reserve(app.Name, "visions-2")
	_, ok := err.(*quota.QuotaExceededError)
	c.Assert(ok, gocheck.Equals, true)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:actions_test.go


示例10: TestReserveUserAppBackward

func (s *S) TestReserveUserAppBackward(c *gocheck.C) {
	user := auth.User{Email: "[email protected]"}
	err := quota.Create(user.Email, 1)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(user.Email)
	app := App{
		Name:     "clap",
		Platform: "django",
	}
	err = quota.Reserve(user.Email, app.Name)
	c.Assert(err, gocheck.IsNil)
	ctx := action.BWContext{
		FWResult: map[string]string{
			"app":  app.Name,
			"user": user.Email,
		},
	}
	reserveUserApp.Backward(ctx)
	err = quota.Reserve(user.Email, app.Name)
	c.Assert(err, gocheck.IsNil)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:actions_test.go


示例11: TestReserveUserAppForwardAppNotPointer

func (s *S) TestReserveUserAppForwardAppNotPointer(c *gocheck.C) {
	user := auth.User{Email: "[email protected]"}
	err := quota.Create(user.Email, 1)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(user.Email)
	app := App{
		Name:     "clap",
		Platform: "django",
	}
	expected := map[string]string{"user": user.Email, "app": app.Name}
	previous, err := reserveUserApp.Forward(action.FWContext{Params: []interface{}{app, user}})
	c.Assert(err, gocheck.IsNil)
	c.Assert(previous, gocheck.DeepEquals, expected)
	err = quota.Reserve(user.Email, "another-app")
	_, ok := err.(*quota.QuotaExceededError)
	c.Assert(ok, gocheck.Equals, true)
	err = quota.Release(user.Email, app.Name)
	c.Assert(err, gocheck.IsNil)
	err = quota.Reserve(user.Email, "another-app")
	c.Assert(err, gocheck.IsNil)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:actions_test.go


示例12: Delete

// Delete deletes an app.
//
// Delete an app is a process composed of four steps:
//
//       1. Destroy the bucket and S3 credentials (if bucket-support is
//       enabled).
//       2. Destroy the app unit using juju
//       3. Unbind all service instances from the app
//       4. Remove the app from the database
func Delete(app *App) error {
	gURL := repository.ServerURL()
	(&gandalf.Client{Endpoint: gURL}).RemoveRepository(app.Name)
	useS3, _ := config.GetBool("bucket-support")
	if useS3 {
		destroyBucket(app)
	}
	if len(app.Units) > 0 {
		Provisioner.Destroy(app)
		app.unbind()
	}
	token := app.Env["TSURU_APP_TOKEN"].Value
	auth.DeleteToken(token)
	quota.Release(app.Owner, app.Name)
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	quota.Delete(app.Name)
	return conn.Apps().Remove(bson.M{"name": app.Name})
}
开发者ID:nemx,项目名称:tsuru,代码行数:31,代码来源:app.go


示例13:

		case *App:
			app = *ctx.Params[0].(*App)
		default:
			return nil, errors.New("First parameter must be App or *App.")
		}
		if limit, err := config.GetUint("quota:units-per-app"); err == nil {
			if limit == 0 {
				return nil, errors.New("app creation is disallowed")
			}
			quota.Create(app.Name, uint(limit))
			quota.Reserve(app.Name, app.Name+"-0")
		}
		return app.Name, nil
	},
	Backward: func(ctx action.BWContext) {
		quota.Delete(ctx.FWResult.(string))
	},
	MinParams: 1,
}

// insertApp is an action that inserts an app in the database in Forward and
// removes it in the Backward.
//
// The first argument in the context must be an App or a pointer to an App.
var insertApp = action.Action{
	Name: "insert-app",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		var app App
		switch ctx.Params[0].(type) {
		case App:
			app = ctx.Params[0].(App)
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:31,代码来源:actions.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang quota.Items函数代码示例发布时间:2022-05-23
下一篇:
Golang quota.Create函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap