本文整理匯總了Golang中appengine/datastore.Delete函數的典型用法代碼示例。如果您正苦於以下問題:Golang Delete函數的具體用法?Golang Delete怎麽用?Golang Delete使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Delete函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Dequeue
func (self *store) Dequeue(perma_blobref string, blobref string) (blobrefs []string, err os.Error) {
parent := datastore.NewKey("perma", perma_blobref, 0, nil)
key := datastore.NewKey("missing", blobref, 0, parent)
var m missingStruct
if err = datastore.Get(self.c, key, &m); err != nil {
if err == datastore.ErrNoSuchEntity {
return nil, nil
}
}
err = datastore.Delete(self.c, key)
if err != nil {
return
}
for _, dep := range m.Pending {
key := datastore.NewKey("pending", dep, 0, parent)
var p pendingStruct
if err = datastore.Get(self.c, key, &m); err != nil {
if err != datastore.ErrNoSuchEntity {
continue
}
}
p.WaitingForCount--
if p.WaitingForCount == 0 {
blobrefs = append(blobrefs, dep)
datastore.Delete(self.c, key)
}
}
return
}
示例2: solve
func solve(w http.ResponseWriter, r *http.Request) {
context := appengine.NewContext(r)
j, err := getParamsJeu(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
context.Errorf("%s", err)
return
}
if j.CheckJeu() == false {
context.Errorf("Données du jeu invalide: Plaques: %d, Total: %d", j.Plaques, j.Total)
w.WriteHeader(http.StatusBadRequest)
return
}
//Generation de la Key
k := genStringID(j)
//Netoyage de pending
err = datastore.RunInTransaction(context, func(c appengine.Context) error {
var err error
key := datastore.NewKey(c, PENDING, k, 0, nil)
if err = datastore.Delete(c, key); err != nil {
return err
}
//Ajout dans ongoing
key = datastore.NewKey(c, ONGOING, k, 0, nil)
if _, err = datastore.Put(c, key, &j); err != nil {
return err
}
//Résolution du compte est bon
var sol solution
sol.Resultats = j.Resolv()
sol.Jeu = j
//Netoyage de ongoing
key = datastore.NewKey(c, ONGOING, k, 0, nil)
if err = datastore.Delete(c, key); err != nil {
return err
}
//Ajout dans finised
key = datastore.NewKey(c, FINISHED, k, 0, nil)
if _, err = datastore.Put(c, key, &sol); err != nil {
return err
}
return err
}, &datastore.TransactionOptions{XG: true})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
context.Errorf("%s", err)
return
}
return
}
示例3: Delete
// Delete deletes a single record of this type. Returns nil if successful, otherwise
// the datastore error that was returned.
// people := NewModel("people")
// people.Delete(1)
//
// Raises events:
// Model.BeforeDelete with Args(id, nil)
// Model.AfterDelete with Args(id, nil)
// Note: The Record will not be passed to the events.
func (m *Model) Delete(id int64) os.Error {
// trigger the BeforeDeleteByID event
context := m.BeforeDelete.Trigger(id, nil)
if !context.Cancel {
err := datastore.Delete(m.AppEngineContext(), m.NewKeyWithID(id))
if err == nil {
// trigger the AfterDeleteByID event
if m.AfterDelete.HasCallbacks() {
m.AfterDelete.TriggerWithContext(context)
}
}
// return the error
return err
}
return ErrOperationCancelledByEventCallback
}
示例4: findValidBid
// Finds the first matching hot bid in the list, and deletes it. Then, returns
// the corresponding "real" bid.
func findValidBid(c appengine.Context, iter *datastore.Iterator, now time.Time) (*datastore.Key, *Bid, error) {
for {
var hot hotBid
key, e := iter.Next(hotBidCodec{&hot})
if e == datastore.Done {
break
} else if e != nil {
// Error case
return nil, nil, e
}
if now.Before(hot.Expires) {
if err := datastore.Delete(c, key); err != nil {
return nil, nil, err
}
var bid Bid
if err := datastore.Get(c, hot.BidKey, bidCodec{&bid}); err != nil {
return nil, nil, err
}
return hot.BidKey, &bid, nil
}
}
return nil, nil, nil
}
示例5: Unlock
func (self *Mutex) Unlock(c gaecontext.GAEContext) (err error) {
if err = datastore.Delete(c, lockIdForName(c, self.Name)); err != nil {
return
}
err = memcache.Del(c, lockKeyForName(self.Name))
return
}
示例6: Cardsetdetail
func Cardsetdetail(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
// get key
encodedKey := r.FormValue("key")
decodedKey, err := datastore.DecodeKey(encodedKey)
if err != nil {
err.Error()
}
// delete mode
if r.FormValue("action") == "delete" {
err = datastore.Delete(c, decodedKey)
if err != nil {
err.Error()
}
http.Redirect(w, r, "/cardsetlist", 303)
}
// get cardset
cardset := new(Cardset)
err = datastore.Get(c, decodedKey, cardset)
if err != nil {
err.Error()
}
// output html
material := make(map[string]string)
material["Name"] = cardset.Name
material["Key"] = encodedKey
Output(w, "page/cardset/cardsetdetail.html", material)
}
示例7: RewriteID
// RewriteID transactionally rewrites the Account under the
// correct (i.e., obfuscated) key.
func (a *Account) RewriteID(c appengine.Context, u *user.User) error {
var err error
a.ID, err = ID(u)
if err != nil {
return fmt.Errorf("couldn't create ID for %v", u)
}
var txnErr error
for i := 0; i < 10; i++ {
txnErr = datastore.RunInTransaction(c, func(c appengine.Context) error {
if err := a.Put(c); err != nil {
return err
}
oldKey := datastore.NewKey(c, "UserAccount", u.ID, 0, nil)
if err := datastore.Delete(c, oldKey); err != nil {
return err
}
return nil
}, &datastore.TransactionOptions{XG: true})
if txnErr != datastore.ErrConcurrentTransaction {
break
}
}
if txnErr != nil {
return txnErr
}
return nil
}
示例8: delete
/**
* データストアから指定された単語を削除する
* API
*/
func delete(w http.ResponseWriter, r *http.Request) {
var c appengine.Context
var u *user.User
var query *datastore.Query
var word string
var iterator *datastore.Iterator
var key *datastore.Key
var err error
var entity Entity
word = r.FormValue("word")
if word == "" {
return
}
c = appengine.NewContext(r)
u = user.Current(c)
query = datastore.NewQuery("words").Filter("UserID =", u.ID).Filter("Word =", word)
iterator = query.Run(c)
for {
key, err = iterator.Next(&entity)
if err != nil {
break
}
err = datastore.Delete(c, key)
Check(c, err)
}
}
示例9: DeleteInvestment
func DeleteInvestment(c appengine.Context, key string) error {
k, err := datastore.DecodeKey(key)
if err != nil {
return err
}
return datastore.Delete(c, k)
}
示例10: deleteOneItem
func deleteOneItem(rw http.ResponseWriter, req *http.Request, keyString string) {
// To access datastore and to log
c := appengine.NewContext(req)
c.Infof("deleteOneItem()")
// Result
r := http.StatusNoContent
defer func() {
// Return status. WriteHeader() must be called before call to Write
if r == http.StatusNoContent {
rw.WriteHeader(http.StatusNoContent)
} else {
http.Error(rw, http.StatusText(r), r)
}
}()
key, err := datastore.DecodeKey(keyString)
if err != nil {
c.Errorf("%s in decoding key string", err)
r = http.StatusBadRequest
return
}
// Delete the entity
if err := datastore.Delete(c, key); err != nil {
c.Errorf("%s, in deleting entity by key", err)
r = http.StatusNotFound
return
}
c.Infof("Key %s is deleted", keyString)
}
示例11: delete
func delete(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
var dTile Tile
// var now Period
// datastore.Get(c, currentSemesterKey(c), &now)
num, e := strconv.Atoi(r.FormValue("num"))
sem, e1 := strconv.Atoi(r.FormValue("semester"))
yr, e2 := strconv.Atoi(r.FormValue("year"))
if e != nil || e1 != nil || e2 != nil {
panic("shouldn't happen; semester and year guaranteed to be ints")
}
k := datastore.NewKey(c, "Tile", strint(r.FormValue("name"), num), 0, tileRootKey(c, sem, yr))
datastore.Get(c, k, &dTile)
if u := user.Current(c); !u.Admin {
http.Redirect(w, r, "/", http.StatusFound)
return
} else {
log.Println("deleting things now...")
e1 := blobstore.Delete(c, appengine.BlobKey(dTile.Imgref))
e2 := datastore.Delete(c, k)
if e1 != nil {
log.Println("error with blobstore delete")
}
if e2 != nil {
log.Println("error with datastore delete")
}
}
log.Println("redirecting")
http.Redirect(w, r, "/", http.StatusFound)
}
示例12: deleteGame
/**
* データストアからゲームを削除する
* 削除を命令したユーザとゲームの所有者が一致していることを事前に確認すること
* この関數內ではチェックを行わない
* @param {string} encodedGameKey エンコード済みのゲームキー
*/
func (this *Model) deleteGame(encodedGameKey string) {
gameKey, err := datastore.DecodeKey(encodedGameKey)
check(this.c, err)
err = datastore.Delete(this.c, gameKey)
check(this.c, err)
}
示例13: deleteAllItem
func deleteAllItem(rw http.ResponseWriter, req *http.Request) {
// To access datastore and to log
c := appengine.NewContext(req)
c.Infof("deleteAll()")
// Delete root entity after other entities
r := 0
pKey := datastore.NewKey(c, ItemKind, ItemRoot, 0, nil)
if keys, err := datastore.NewQuery(ItemKind).KeysOnly().GetAll(c, nil); err != nil {
c.Errorf("%s", err)
r = 1
} else if err := datastore.DeleteMulti(c, keys); err != nil {
c.Errorf("%s", err)
r = 1
} else if err := datastore.Delete(c, pKey); err != nil {
c.Errorf("%s", err)
r = 1
}
// Return status. WriteHeader() must be called before call to Write
if r == 0 {
rw.WriteHeader(http.StatusOK)
} else {
http.Error(rw, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
}
示例14: updateArticles
func (f FeedInfo) updateArticles(c appengine.Context, articles Articles) error {
key := datastore.NewKey(c, feedKind, f.Url, 0, nil)
q := datastore.NewQuery(articleKind).Ancestor(key).KeysOnly()
stored := make(map[string]*datastore.Key)
for it := q.Run(c); ; {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
return err
}
stored[k.StringID()] = k
}
for _, a := range articles {
k := datastore.NewKey(c, articleKind, a.StringID(), 0, key)
id := k.StringID()
if _, ok := stored[id]; ok {
delete(stored, id)
continue
}
if _, err := datastore.Put(c, k, &a); err != nil {
return err
}
}
for _, k := range stored {
if err := datastore.Delete(c, k); err != nil {
return err
}
}
return nil
}
示例15: Delete
func (t *Team) Delete(c appengine.Context) {
err := datastore.Delete(c, t.Key)
if err != nil {
c.Errorf("Error: %v", err)
return
}
}