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

Golang datastore.Delete函数代码示例

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

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



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

示例1: Remove

func (fs *dsFileSys) Remove(name string) error {

	// log.Printf("trying to remove %-20v", name)
	f, err := fs.fileByPath(name)
	if err == nil {
		// log.Printf("   found file %v", f.Dir+f.BName)
		// log.Printf("   fkey %-26v", f.Key)
		err = datastore.Delete(fs.Ctx(), f.Key)
		if err != nil {
			return fmt.Errorf("error removing file %v", err)
		}
	}

	d, err := fs.dirByPath(name)
	if err == nil {
		// log.Printf("   dkey %v", d.Key)
		err = datastore.Delete(fs.Ctx(), d.Key)
		d.MemCacheDelete()
		if err != nil {
			return fmt.Errorf("error removing dir %v", err)
		}
	}

	return nil

}
开发者ID:aarzilli,项目名称:tools,代码行数:26,代码来源:30_fs_impl.go


示例2: deleteHandler

func deleteHandler(w http.ResponseWriter, r *http.Request) {
	strThread := r.FormValue("thread")
	c := appengine.NewContext(r)
	threadId, _ := strconv.Atoi(strThread)

	q := datastore.NewQuery(WebSubmissionEntityName).
		Filter("Thread =", int64(threadId))

	//TODO cleanup checks whatever for emtpy or otherwise other than 1 result
	t := q.Run(c)

	var x WebSubmission
	key, err := t.Next(&x)
	if err != nil {
		serveError(c, w, err)
		fmt.Fprintf(w, "nope %v", err.Error())
		return
	}

	err2 := datastore.Delete(c, key)
	if err != nil {
		serveError(c, w, err2)
		return
	}

	http.Redirect(w, r, "/", http.StatusFound)
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:27,代码来源:main.go


示例3: revert

// revert modifies Idiom and deletes IdiomHistory, but not in a transaction (for now)
func (a *GaeDatastoreAccessor) revert(c context.Context, idiomID int, version int) (*Idiom, error) {
	q := datastore.NewQuery("IdiomHistory").
		Filter("Id =", idiomID).
		Order("-Version").
		Limit(2)
	histories := make([]*IdiomHistory, 0)
	historyKeys, err := q.GetAll(c, &histories)
	if err != nil {
		return nil, err
	}
	if len(histories) == 0 {
		return nil, PiError{ErrorText: fmt.Sprintf("No history found for idiom %v", idiomID), Code: 400}
	}
	if len(histories) == 1 {
		return nil, PiError{ErrorText: fmt.Sprintf("Can't revert the only version of idiom %v", idiomID), Code: 400}
	}
	if histories[0].Version != version {
		return nil, PiError{ErrorText: fmt.Sprintf("Can't revert idiom %v: last version is not %v", idiomID, version), Code: 400}
	}
	log.Infof(c, "Reverting idiom %v from version %v to version %v", idiomID, histories[0].Version, histories[1].Version)
	idiomKey := newIdiomKey(c, idiomID)
	idiom := &histories[1].Idiom
	_, err = datastore.Put(c, idiomKey, idiom)
	if err != nil {
		return nil, err
	}
	return idiom, datastore.Delete(c, historyKeys[0])
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:29,代码来源:dataAccessorGae.go


示例4: unfollow

func unfollow(res http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	ctx := appengine.NewContext(req)
	// get session
	memItem, err := getSession(req)
	if err != nil {
		log.Infof(ctx, "Attempt to unfollow from logged out user")
		http.Error(res, "You must be logged in", http.StatusForbidden)
		return
	}
	// declare a variable of type user
	// initialize user with values from memcache item
	var user User
	json.Unmarshal(memItem.Value, &user)
	// get the datastore key for the follower
	followerKey := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	// get a datastore key for the followee
	followeeKey := datastore.NewKey(ctx, "Follows", ps.ByName("user"), 0, followerKey)
	// delete entry in datastore
	err = datastore.Delete(ctx, followeeKey)
	if err != nil {
		log.Errorf(ctx, "error deleting followee: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}
	http.Redirect(res, req, "/user/"+ps.ByName("user"), 302)
}
开发者ID:RobertoSuarez,项目名称:GolangTraining,代码行数:26,代码来源:api.go


示例5: serveDocumentsDelete

func serveDocumentsDelete(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
	serveAPI(res, req, func() interface{} {
		ctx := appengine.NewContext(req)
		session, _ := sessionStore.Get(req, "session")

		email, ok := session.Values["email"].(string)
		if !ok {
			return HTTPError{403, "access denied"}
		}

		id := params.ByName("id")
		userKey := datastore.NewKey(ctx, "User", email, 0, nil)
		docKey := datastore.NewKey(ctx, "Document", id, 0, userKey)
		var document Document
		err := datastore.Get(ctx, docKey, &document)
		if err != nil {
			return err
		}
		err = datastore.Delete(ctx, docKey)
		if err != nil {
			return err
		}
		return true
	})
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:25,代码来源:api.go


示例6: deleteData

func deleteData(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	u := user.Current(ctx)
	keyVal := req.FormValue("keyVal")
	key, err := datastore.DecodeKey(keyVal)
	if err != nil {
		http.Error(res, "Invalid data", http.StatusBadRequest)
		log.Warningf(ctx, err.Error())
		return
	}
	var l list
	err = datastore.Get(ctx, key, &l)
	if err != nil {
		http.Error(res, "Invalid data", http.StatusBadRequest)
		log.Warningf(ctx, err.Error())
		return
	}
	if l.Owner != u.Email {
		http.Error(res, "Not authorized to delete this entry", http.StatusUnauthorized)
		log.Warningf(ctx, err.Error())
		return
	}
	err = datastore.Delete(ctx, key)
	if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Errorf(ctx, err.Error())
		return
	}
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:29,代码来源:main.go


示例7: RemoveAuthorize

func (s *DatastoreStorage) RemoveAuthorize(code string) error {
	log.Infof(s.ctx, "RemoveAuthorize(%s)\n", code)

	k := datastore.NewKey(s.ctx, "Authorize", code, 0, nil)
	if err := datastore.Delete(s.ctx, k); err != nil {
		return err
	}
	return nil
}
开发者ID:imtheoperator,项目名称:osin-datastore,代码行数:9,代码来源:dsstorage.go


示例8: Remove

//Remove removes a card from the datastore, memcache, and stripe
func Remove(w http.ResponseWriter, r *http.Request) {
	//get form values
	datastoreId := r.FormValue("customerId")
	datastoreIdInt, _ := strconv.ParseInt(datastoreId, 10, 64)

	//make sure an id was given
	if len(datastoreId) == 0 {
		output.Error(ErrMissingInput, "A customer's datastore ID must be given but was missing. This value is different from your \"Customer ID\" and should have been submitted automatically.", w, r)
		return
	}

	//init stripe
	c := appengine.NewContext(r)
	sc := createAppengineStripeClient(c)

	//delete customer on stripe
	custData, err := findByDatastoreId(c, datastoreIdInt)
	if err != nil {
		output.Error(err, "An error occured while trying to look up customer's Stripe information.", w, r)
	}
	stripeCustId := custData.StripeCustomerToken
	sc.Customers.Del(stripeCustId)

	//delete custome from datastore
	completeKey := getCustomerKeyFromId(c, datastoreIdInt)
	err = datastore.Delete(c, completeKey)
	if err != nil {
		output.Error(err, "There was an error while trying to delete this customer. Please try again.", w, r)
		return
	}

	//delete customer from memcache
	//delete list of cards in memcache since this list is now stale
	//all memcache.Delete operations are listed first so error handling doesn't return if one fails...each call does not depend on another so this is safe
	//obviously, if the card is not in the cache it cannot be removed
	err1 := memcache.Delete(c, datastoreId)
	err2 := memcache.Delete(c, custData.CustomerId)
	err3 := memcache.Delete(c, listOfCardsKey)
	if err1 != nil && err1 != memcache.ErrCacheMiss {
		output.Error(err1, "There was an error flushing this card's data from the cache (by datastore id). Please contact an administrator and have them flush the cache manually.", w, r)
		return
	}
	if err2 != nil && err2 != memcache.ErrCacheMiss {
		output.Error(err2, "There was an error flushing this card's data from the cache (by customer id). Please contact an administrator and have them flush the cache manually.", w, r)
		return
	}
	if err3 != nil && err3 != memcache.ErrCacheMiss {
		output.Error(err3, "There was an error flushing the cached list of cards.", w, r)
		return
	}

	//customer removed
	//return to client
	output.Success("removeCustomer", nil, w)
	return
}
开发者ID:coreymgilmore,项目名称:stripe-appengine-frontend,代码行数:57,代码来源:card-remove.go


示例9: deleteTask

func deleteTask(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	c := appengine.NewContext(r)
	id, _ := strconv.ParseInt(params.ByName("id"), 10, 64)
	key := datastore.NewKey(c, "tasks", "", id, nil)
	if err := datastore.Delete(c, key); err != nil {
		sendJSONResponse(w, http.StatusNotModified, nil)
	} else {
		sendJSONResponse(w, http.StatusAccepted, nil)
	}
}
开发者ID:DrenBx,项目名称:Go-TodoAPI,代码行数:10,代码来源:task.go


示例10: submissionsAddHandler

func submissionsAddHandler(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)
	if err := r.ParseForm(); err != nil {
		serveErr(ctx, err, w)
		return
	}

	ID, _, err := datastore.AllocateIDs(ctx, "Podcast", nil, 1)
	if err != nil {
		serveErr(ctx, err, w)
		return
	}

	date, err := time.Parse(yyyymmdd, r.FormValue("date"))
	if err != nil {
		serveErr(ctx, err, w)
		return
	}

	podcast := Podcast{
		ID:         ID,
		Show:       r.FormValue("show"),
		Title:      r.FormValue("title"),
		Desc:       r.FormValue("desc"),
		URL:        template.URL(r.FormValue("url")),
		MediaURL:   template.URL(r.FormValue("media_url")),
		RuntimeSec: r.FormValue("runtime"),
		Size:       r.FormValue("size"),
		Date:       date,
		Added:      time.Now(),
	}

	if _, err := datastore.Put(ctx, datastore.NewKey(ctx, "Podcast", "", ID, nil), &podcast); err != nil {
		serveErr(ctx, err, w)
		return
	}

	key, err := datastore.DecodeKey(r.FormValue("key"))
	if err != nil {
		serveErr(ctx, err, w)
		return
	}

	if err := datastore.Delete(ctx, key); err != nil {
		serveErr(ctx, err, w)
		return
	}

	if err := memcache.Delete(ctx, cacheKey); err != nil {
		log.Errorf(ctx, "memcache delete error %v", err)
	}

	successTmpl.ExecuteTemplate(w, "base", nil)
}
开发者ID:rojters,项目名称:gopherpods,代码行数:54,代码来源:gopherpods.go


示例11: Delete

// Delete deletes the record based on the provided key.
//
func (goal *Goal) Delete(c context.Context) (err error) {
	// TODO: need to check for existance before deleting. if NOT exists, then throw ErrorNoMatch error (err = ErrorNoMatch)
	if err = goal.Get(c); err == types.ErrorNoMatch {
		return
	}

	key := datastore.NewKey(c, "Goal", util.StringKey(goal.Name), 0, nil)

	err = datastore.Delete(c, key)

	return
}
开发者ID:muly,项目名称:lifelog,代码行数:14,代码来源:goal.go


示例12: deleteIdiom

func (a *GaeDatastoreAccessor) deleteIdiom(c context.Context, idiomID int, why string) error {
	key, _, err := a.getIdiom(c, idiomID)
	if err != nil {
		return err
	}
	// Remove from text search index
	err = a.unindex(c, idiomID)
	if err != nil {
		log.Errorf(c, "Failed to unindex idiom %d: %v", idiomID, err)
	}
	return datastore.Delete(c, key)
	// The why param is ignored for now, because idiom doesn't exist anymore.
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:13,代码来源:dataAccessorGae.go


示例13: adminDeleteTask

func adminDeleteTask(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	tid := r.FormValue("taskKey")

	k, err := datastore.DecodeKey(tid)
	if err != nil {
		panic(err)
	}

	if err := datastore.Delete(c, k); err != nil {
		panic(err)
	}

	w.WriteHeader(204)
}
开发者ID:dustin,项目名称:sallingshome,代码行数:16,代码来源:admin.go


示例14: TestPostCompany

func TestPostCompany(t *testing.T) {
	company := model.Company{
		Address: mail.Address{
			Name:    "companyName",
			Address: "[email protected]",
		},
	}

	r, err := http.NewRequest("POST", "/companies", requestBody(t, company))
	if err != nil {
		t.Fatal(err)
	}
	loginAsCompanyUser(r)
	rr := record(t, r)
	testRequestStatus(t, rr, 200, "Should be okay.")

	// Check the entity the client recieves was indeed saved in the datastore.
	var companyResponse = struct {
		Name, Address, Nick, Key string
	}{}

	if err = json.NewDecoder(rr.Body).Decode(&companyResponse); err != nil {
		t.Fatal(err)
	}

	var key *datastore.Key
	key, err = datastore.DecodeKey(companyResponse.Key)
	if err != nil {
		t.Fatal(err)
	}

	ctx := backgroundContext()

	var savedCompany model.Company

	err = datastore.Get(ctx, key, &savedCompany)
	if err != nil {
		t.Fatal(err)
	}

	if savedCompany.Address != company.Address {
		t.Fatal("Saved company is wrong")
	}

	datastore.Delete(ctx, key)
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:46,代码来源:company_test.go


示例15: DeleteProfile

func DeleteProfile(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
	if r.Method != "DELETE" {
		return http.StatusMethodNotAllowed, nil
	}

	key, err := datastore.DecodeKey(mux.Vars(r)["key"])

	if err != nil {
		return http.StatusBadRequest, err
	}

	if err = datastore.Delete(ctx, key); err != nil {
		return http.StatusInternalServerError, err
	}

	return http.StatusOK, nil
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:17,代码来源:profile.go


示例16: Delete

// delete world data
func (a *MinecraftApi) Delete(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)

	u := user.Current(ctx)
	if u == nil {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(http.StatusUnauthorized)
		loginURL, err := user.LoginURL(ctx, "")
		if err != nil {
			log.Errorf(ctx, "get user login URL error, %s", err.Error())
			w.WriteHeader(http.StatusInternalServerError)
			return
		}
		w.Write([]byte(fmt.Sprintf(`{"loginURL":"%s"}`, loginURL)))
		return
	}
	if user.IsAdmin(ctx) == false {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(http.StatusForbidden)
		return
	}

	keyStr := r.FormValue("key")

	key, err := datastore.DecodeKey(keyStr)
	if err != nil {
		log.Infof(ctx, "invalid key, %v", r.Body)
		w.WriteHeader(http.StatusBadRequest)
		w.Write([]byte(`{"message": "invalid key."}`))
		return
	}

	err = datastore.RunInTransaction(ctx, func(c context.Context) error {
		return datastore.Delete(ctx, key)
	}, nil)
	if err != nil {
		log.Errorf(ctx, "Minecraft Delete Error. error = %s", err.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.WriteHeader(http.StatusOK)
	json.NewEncoder(w).Encode(`{}`)
}
开发者ID:sinmetal,项目名称:sinmetalcraft,代码行数:46,代码来源:sinmetalcraft.go


示例17: deleteHandler

func deleteHandler(w http.ResponseWriter, r *http.Request) {

	urls := strings.Split(r.URL.Path, "/")
	keyId := urls[4]

	c := appengine.NewContext(r)
	k := datastore.NewKey(c, "Slide", keyId, 0, nil)

	//err
	err := datastore.Delete(c, k)
	if err != nil {
		errorPage(w, "Delete Error", "Slide Delete", err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/me/", 301)
	return
}
开发者ID:shizuokago,项目名称:gopredit,代码行数:18,代码来源:slide.go


示例18: handleFilesItem

func handleFilesItem(w http.ResponseWriter, r *http.Request) {
	id := r.URL.Path
	if id == "" {
		w.WriteHeader(404)
		return
	}
	c := appengine.NewContext(r)
	key := datastore.NewKey(c, "File", id, 0, nil)
	switch r.Method {
	case "GET":
		var file File
		err := datastore.Get(c, key, &file)
		if err == datastore.ErrNoSuchEntity {
			http.NotFound(w, r)
			return
		}
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "query file: %s", err.Error())
			return
		}
		w.Header().Set("Content-Type", "application/json")
		err = json.NewEncoder(w).Encode(&file)
		if err != nil {
			log.Errorf(c, "json encode: %s", err.Error())
		}
	case "DELETE":
		err := datastore.Delete(c, key)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Errorf(c, "delete file: %s", err.Error())
			return
		}
		err = blobstore.Delete(c, appengine.BlobKey(id))
		if err != nil {
			log.Warningf(c, "delete file '%s': %s", id, err.Error())
		}
		w.WriteHeader(204)
	default:
		http.Error(w, "Valid methods are GET and DELETE", http.StatusMethodNotAllowed)
		return
	}
}
开发者ID:mastercactapus,项目名称:ae-gallery,代码行数:43,代码来源:admin.go


示例19: delete

func delete(w http.ResponseWriter, r *http.Request) {
	address, err := mail.ParseAddress(r.FormValue("email"))

	if err != nil {
		http.Error(w, "Invalid email address: "+err.Error(), 422)
		return
	}

	token, err := hex.DecodeString(r.FormValue("token"))

	if err != nil {
		http.Error(w, "Invalid token: "+err.Error(), 422)
		return
	}

	c := appengine.NewContext(r)
	q := datastore.NewQuery("subscription").Filter("Address =", address.Address).Limit(1)

	var subs []Subscription
	keys, err := q.GetAll(c, &subs)

	if len(subs) != 1 {
		http.Error(w, "Unable to identify your subscription. Got "+fmt.Sprintf("%d", len(subs))+" matches on "+address.Address, http.StatusInternalServerError)
		return
	}

	sub := subs[0]

	if !bytes.Equal(sub.Token, token) {
		http.Error(w, "Forbidden", http.StatusUnauthorized)
		return
	}

	err = datastore.Delete(c, keys[0])

	if err != nil {
		http.Error(w, "Failed to delete your subscription. Please contact [email protected]", http.StatusInternalServerError)
		return
	}

	w.Write([]byte("Your subscription was removed, we're sorry to see you go :("))
}
开发者ID:pbochis,项目名称:api,代码行数:42,代码来源:sub.go


示例20: submissionsDelHandler

func submissionsDelHandler(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)
	if err := r.ParseForm(); err != nil {
		serveErr(ctx, err, w)
		return
	}

	key, err := datastore.DecodeKey(r.FormValue("key"))
	if err != nil {
		serveErr(ctx, err, w)
		return
	}

	if err := datastore.Delete(ctx, key); err != nil {
		serveErr(ctx, err, w)
		return
	}

	successTmpl.ExecuteTemplate(w, "base", nil)
}
开发者ID:rojters,项目名称:gopherpods,代码行数:20,代码来源:gopherpods.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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