本文整理汇总了Golang中google/golang.org/appengine/datastore.Delete函数的典型用法代码示例。如果您正苦于以下问题:Golang Delete函数的具体用法?Golang Delete怎么用?Golang Delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
示例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])
}
示例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)
}
示例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
})
}
示例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
}
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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.
}
示例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)
}
示例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)
}
示例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
}