本文整理匯總了Golang中appengine/datastore.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Get函數的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: TouchSuc
func TouchSuc(c appengine.Context, IdSuc string, IdEmp string) error {
/* llave de Cta-Empresa */
ce := &CtaEmpresa{IdEmp: IdEmp}
ceKey := datastore.NewKey(c, "CtaEmpresa", ce.IdEmp, 0, nil)
err := datastore.Get(c, ceKey, ce)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* parent de Empresa */
cta := &Cta{Email: ce.Email}
ctaKey := datastore.NewKey(c, "Cta", cta.Email, 0, nil)
err = datastore.Get(c, ctaKey, cta)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* Key de empresa */
empKey := datastore.NewKey(c, "Empresa", IdEmp, 0, ctaKey)
suc := &Sucursal{IdSuc: IdSuc}
sucKey := datastore.NewKey(c, "Sucursal", IdSuc, 0, empKey)
err = datastore.Get(c, sucKey, suc)
if err == datastore.ErrNoSuchEntity {
return err
}
suc.FechaHora = time.Now().Add(time.Duration(GMTADJ) * time.Second)
if _, err = datastore.Put(c, sucKey, suc); err != nil {
return err
}
return nil
}
示例3: edit
func edit(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
var now Period
datastore.Get(c, currentSemesterKey(c), &now)
arr := regexp.MustCompile("_").Split(r.FormValue("id"), 4)
name := arr[0]
count, cnterr := strconv.Atoi(arr[1])
if cnterr != nil {
log.Println("Something failed with counting for some reason")
}
sem, e1 := strconv.Atoi(arr[2])
yr, e2 := strconv.Atoi(arr[3])
if e1 != nil || e2 != nil {
panic("neither year nor sem should be non-ints")
}
if now.Semester == sem && now.Year == yr {
value := r.FormValue("value")
k := datastore.NewKey(c, "Tile", strint(name, count), 0, tileRootKey(c, sem, yr))
var uTile Tile
datastore.Get(c, k, &uTile)
// log.Println(lcs.Diff(value, uTile.Desc))
uTile.Desc = value
uTile.LastUpdate = time.Now()
datastore.Put(c, k, &uTile)
w.Write([]byte(uTile.Desc))
} else {
w.Write([]byte("Edits discarded: cannot edit entries after the semester has ended"))
}
}
示例4: logHandler
// logHandler displays log text for a given hash.
// It handles paths like "/log/hash".
func logHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "text/plain; charset=utf-8")
c := contextForRequest(r)
hash := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:]
key := datastore.NewKey(c, "Log", hash, 0, nil)
l := new(Log)
if err := datastore.Get(c, key, l); err != nil {
if err == datastore.ErrNoSuchEntity {
// Fall back to default namespace;
// maybe this was on the old dashboard.
c := appengine.NewContext(r)
key := datastore.NewKey(c, "Log", hash, 0, nil)
err = datastore.Get(c, key, l)
}
if err != nil {
logErr(w, r, err)
return
}
}
b, err := l.Text()
if err != nil {
logErr(w, r, err)
return
}
w.Write(b)
}
示例5: Increment
// Increment increments the named counter.
func Increment(c appengine.Context, name string) error {
// Get counter config.
var cfg counterConfig
ckey := datastore.NewKey(c, configKind, name, 0, nil)
err := datastore.RunInTransaction(c, func(c appengine.Context) error {
err := datastore.Get(c, ckey, &cfg)
if err == datastore.ErrNoSuchEntity {
cfg.Shards = defaultShards
_, err = datastore.Put(c, ckey, &cfg)
}
return err
}, nil)
if err != nil {
return err
}
err = datastore.RunInTransaction(c, func(c appengine.Context) error {
shardName := fmt.Sprintf("%v%d", name, rand.Intn(cfg.Shards))
key := datastore.NewKey(c, shardKind, shardName, 0, nil)
var s shard
err := datastore.Get(c, key, &s)
// A missing entity and a present entity will both work.
if err != nil && err != datastore.ErrNoSuchEntity {
return err
}
s.Count++
s.Name = name
_, err = datastore.Put(c, key, &s)
return err
}, nil)
if err != nil {
return err
}
//memcache.Increment(c, memcacheKey(name), 1, 0)
return nil
}
示例6: GetEmpresa
// Métodos de Empresa
func GetEmpresa(c appengine.Context, id string) *Empresa {
/* llave de Cta-Empresa */
ce := &CtaEmpresa{IdEmp: id}
ceKey := datastore.NewKey(c, "CtaEmpresa", ce.IdEmp, 0, nil)
err := datastore.Get(c, ceKey, ce)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* parent de Empresa */
cta := &Cta{Email: ce.Email}
ctaKey := datastore.NewKey(c, "Cta", cta.Email, 0, nil)
err = datastore.Get(c, ctaKey, cta)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* Key de empresa */
emp := &Empresa{IdEmp: id}
empKey := datastore.NewKey(c, "Empresa", emp.IdEmp, 0, ctaKey)
err = datastore.Get(c, empKey, emp)
if err == datastore.ErrNoSuchEntity {
return nil
}
return emp
}
示例7: GetEmpSucursales
func GetEmpSucursales(c appengine.Context, IdEmp string) *[]Sucursal {
/* llave de Cta-Empresa */
ce := &CtaEmpresa{IdEmp: IdEmp}
ceKey := datastore.NewKey(c, "CtaEmpresa", ce.IdEmp, 0, nil)
err := datastore.Get(c, ceKey, ce)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* parent de Empresa */
cta := &Cta{Email: ce.Email}
ctaKey := datastore.NewKey(c, "Cta", cta.Email, 0, nil)
err = datastore.Get(c, ctaKey, cta)
if err == datastore.ErrNoSuchEntity {
return nil
}
/* Key de empresa */
empKey := datastore.NewKey(c, "Empresa", IdEmp, 0, ctaKey)
q := datastore.NewQuery("Sucursal").Ancestor(empKey)
n, _ := q.Count(c)
sucursales := make([]Sucursal, 0, n)
if _, err := q.GetAll(c, &sucursales); err != nil {
return nil
}
return &sucursales
}
示例8: acceptSuggestion
func acceptSuggestion(w http.ResponseWriter, r *http.Request) {
if csrf.ValidateToken(r, r.FormValue("CSRFToken")) {
trimPath := strings.Trim(r.URL.Path, "/admin/post/suggestion/accept")
postID, _ := strconv.Atoi(trimPath)
postID64 := int64(postID)
c := appengine.NewContext(r)
keyS := datastore.NewKey(c, "PostSuggestion", "", postID64, nil)
var suggestion PostSuggestion
datastore.Get(c, keyS, &suggestion)
var post Post
keyP := datastore.NewIncompleteKey(c, "Post", nil)
var counter Counter
keyC := datastore.NewKey(c, "Counter", "", 1, nil)
datastore.Get(c, keyC, &counter)
counter.Count = counter.Count + 1
// Add Cache Counter
mCount := new(bytes.Buffer)
encCount := gob.NewEncoder(mCount)
encCount.Encode(counter)
cache.AddCache(r, "Counter", mCount.Bytes())
post.Content = suggestion.Content
post.Sequence = counter.Count
datastore.Put(c, keyP, &post)
datastore.Put(c, keyC, &counter)
datastore.Delete(c, keyS)
http.Redirect(w, r, "/admin/post/suggestion", http.StatusFound)
}
}
示例9: GetProjects
// GetProjects returns all projects owned by the given user.
// Optionally also include projects that are shared with the user.
func GetProjects(user string,
include_shared bool,
c *appengine.Context) ([]*datastore.Key, []*EncodedProject, error) {
qr := datastore.NewQuery("EncodedProject").
Filter("Owner = ", user).
Order("-Created").Limit(100)
keyset := make(map[string]bool)
var projlist []*EncodedProject
keylist, err := qr.GetAll(*c, &projlist)
if err != nil {
(*c).Errorf("GetProjects[1]: %v", err)
return nil, nil, err
}
if !include_shared {
return keylist, projlist, err
}
for _, k := range keylist {
keyset[k.String()] = true
}
// Get project ids that are shared with this user
ky2 := datastore.NewKey(*c, "SharingByUser", strings.ToLower(user),
0, nil)
var spu SharingByUser
err = datastore.Get(*c, ky2, &spu)
if err == datastore.ErrNoSuchEntity {
// No projects shared with this user
return keylist, projlist, nil
}
if err != nil {
(*c).Errorf("GetProjects[2]: %v", err)
return nil, nil, err
}
// Get the shared projects
spvl := Clean_split(spu.Projects, ",")
for _, spv := range spvl {
ky := datastore.NewKey(*c, "EncodedProject", spv, 0, nil)
_, ok := keyset[ky.String()]
if ok {
continue
}
keyset[ky.String()] = true
pr := new(EncodedProject)
err = datastore.Get(*c, ky, pr)
if err != nil {
(*c).Infof("GetProjects [3]: %v\n%v", spv, err)
continue
}
keylist = append(keylist, ky)
projlist = append(projlist, pr)
}
return keylist, projlist, nil
}
示例10: SetProperty
func SetProperty(c appengine.Context, ref ArticleRef, propertyName string, propertyValue bool) ([]string, error) {
articleKey, err := ref.key(c)
if err != nil {
return nil, err
}
article := new(Article)
if err := datastore.Get(c, articleKey, article); err != nil && !IsFieldMismatch(err) {
return nil, err
}
if propertyValue != article.HasProperty(propertyName) {
wasUnread := article.IsUnread()
wasLiked := article.IsLiked()
unreadDelta := 0
article.SetProperty(propertyName, propertyValue)
// Update unread counts if necessary
if wasUnread != article.IsUnread() {
if wasUnread {
unreadDelta = -1
} else {
unreadDelta = 1
}
}
if _, err := datastore.Put(c, articleKey, article); err != nil {
return nil, err
}
if wasLiked != article.IsLiked() {
if wasLiked {
article.updateLikeCount(c, -1)
} else {
article.updateLikeCount(c, 1)
}
}
if unreadDelta != 0 {
// Update unread counts - not critical
subscriptionKey := articleKey.Parent()
subscription := new(Subscription)
if err := datastore.Get(c, subscriptionKey, subscription); err != nil {
c.Warningf("Unread count update failed: subscription read error (%s)", err)
} else if subscription.UnreadCount+unreadDelta >= 0 {
subscription.UnreadCount += unreadDelta
if _, err := datastore.Put(c, subscriptionKey, subscription); err != nil {
c.Warningf("Unread count update failed: subscription write error (%s)", err)
}
}
}
}
return article.Properties, nil
}
示例11: handleOpen
func handleOpen(r *http.Request, c appengine.Context, u *user.User) (
interface{}, error) {
if r.Method != "POST" {
return nil, ErrMethodNotAllowed
}
k, err := ds.DecodeKey(r.FormValue("doorKey"))
if err != nil {
return nil, ErrNoDoorKey
}
cnt := 0
if cnt, err = ds.NewQuery("Permission").
Filter("userKey=", ds.NewKey(c, "User", u.ID, 0, nil)).
Filter("doorKey=", k).
Filter("level>=", LevelOpener).
Count(c); err != nil {
return nil, err
}
if cnt == 0 {
return nil, ErrNoOpenerPermission
}
config := Config{}
if err = ds.Get(c, ds.NewKey(c, "Config", "singleton", 0, nil), &config); err != nil {
if err == ds.ErrNoSuchEntity {
err = ErrNoConfig
}
return nil, err
}
if config.ApiKey == "" {
return nil, ErrNoConfig
}
door := Door{}
if err = ds.Get(c, k, &door); err != nil {
if err == ds.ErrNoSuchEntity {
err = ErrNoOpenerPermission
}
return nil, err
}
client := urlfetch.Client(c)
sender := gcm.Sender{config.ApiKey, client}
msg := &gcm.Message{
RegistrationIDs: []string{door.RegId},
Data: map[string]string{"action": "OPEN"}}
var response *gcm.Response
response, err = sender.SendNoRetry(msg)
if err != nil {
c.Errorf("Error while sending message to GCM service: %s", err.Error())
return nil, Err{"Failed to open door.", http.StatusInternalServerError}
}
return response, nil
}
示例12: Increment
// Increment increments the named counter.
func Increment(c appengine.Context, valName string) error {
// Get counter config.
wNumShards := dsu.WrapInt{}
dsu.McacheGet(c, mCKNumShards(valName), &wNumShards)
if wNumShards.I < 1 {
ckey := datastore.NewKey(c, dsKindNumShards, mCKNumShards(valName), 0, nil)
errTx := datastore.RunInTransaction(c,
func(c appengine.Context) error {
err := datastore.Get(c, ckey, &wNumShards)
if err == datastore.ErrNoSuchEntity {
wNumShards.I = defaultNumShards
_, err = datastore.Put(c, ckey, &wNumShards)
}
return err
}, nil)
if errTx != nil {
return errTx
}
dsu.McacheSet(c, mCKNumShards(valName), dsu.WrapInt{wNumShards.I})
}
// pick random counter and increment it
errTx := datastore.RunInTransaction(c,
func(c appengine.Context) error {
shardId := rand.Intn(wNumShards.I)
dsKey := datastore.NewKey(c, dsKindShard, dSKSingleShard(valName, shardId), 0, nil)
var sd WrapShardData
err := datastore.Get(c, dsKey, &sd)
// A missing entity and a present entity will both work.
if err != nil && err != datastore.ErrNoSuchEntity {
return err
}
sd.Name = valName
sd.ShardId = shardId
sd.I++
_, err = datastore.Put(c, dsKey, &sd)
c.Infof("ds put %v %v", dsKey, sd)
return err
}, nil)
if errTx != nil {
return errTx
}
memcache.Increment(c, mCKValue(valName), 1, 0)
// collect number of updates
// per valName per instance in memory
// for every interval of 10 minutes
//
// a batch job checks if the number of shards should be increased or decreased
// and truncates this map
updateSamplingFrequency[valName+util.TimeMarker()[:len("2006-01-02 15:0")]] += 1
return nil
}
示例13: viewpage
func viewpage(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
url := r.URL.Path[len(viewpage_prefix):]
if url == "" || strings.HasSuffix(url, "/") {
url += "index"
}
hostkey := datastore.NewKey(c, "Host", r.URL.Host+"/", 0, nil)
// check for a static first
static := &Static{Url: url}
key := datastore.NewKey(c, "Static", static.Key(), 0, hostkey)
err := datastore.Get(c, key, static)
if err != nil && err != datastore.ErrNoSuchEntity {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else if err == nil {
static.PostLoad()
// guess the MIME type based on the extension
if dot := strings.LastIndex(static.Url, "."); dot >= 0 && len(static.Url) > dot+1 {
ext := static.Url[dot:]
if mimetype := mime.TypeByExtension(ext); mimetype != "" {
w.Header()["Content-Type"] = []string{mimetype}
} else {
w.Header()["Content-Type"] = []string{http.DetectContentType(static.Contents)}
}
}
w.Write(static.Contents)
return
}
// try a rendered page
page := NewPage(url)
if !page.Validate() {
http.Error(w, "Invalid page URL", http.StatusBadRequest)
return
}
// get the page
key = datastore.NewKey(c, "Page", page.Key(), 0, hostkey)
err = datastore.Get(c, key, page)
if err != nil && err == datastore.ErrNoSuchEntity {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
} else if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
page.PostLoad()
page.Render()
if err = render(c, w, r.URL.Host, page); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
示例14: Remove_sharing
// Remove_sharing removes the given users from the access list for the given project.
func Remove_sharing(project_name string,
user_names []string,
c *appengine.Context) error {
// Map whose keys are the users to remove.
rmu := make(map[string]bool)
for i := 0; i < len(user_names); i++ {
rmu[user_names[i]] = true
}
// Update SharingByProject.
key := datastore.NewKey(*c, "SharingByProject", project_name, 0, nil)
sproj := new(SharingByProject)
err := datastore.Get(*c, key, sproj)
if err == datastore.ErrNoSuchEntity {
// OK
} else if err != nil {
return err
} else {
users := Clean_split(sproj.Users, ",")
users = unique_svec(users)
users = sdiff(users, rmu)
sproj.Users = strings.Join(users, ",")
_, err = datastore.Put(*c, key, sproj)
if err != nil {
return err
}
}
// Update SharingByUser.
for _, name := range user_names {
pkey := datastore.NewKey(*c, "SharingByUser", strings.ToLower(name), 0, nil)
suser := new(SharingByUser)
err := datastore.Get(*c, pkey, suser)
if err == datastore.ErrNoSuchEntity {
// should not reach here
} else if err != nil {
return err
} else {
projlist := Clean_split(suser.Projects, ",")
projlist = unique_svec(projlist)
projlist = sdiff(projlist, map[string]bool{project_name: true})
suser.Projects = strings.Join(projlist, ",")
_, err = datastore.Put(*c, pkey, suser)
if err != nil {
return err
}
}
}
return nil
}
示例15: SetTags
func SetTags(c appengine.Context, ref ArticleRef, tags []string) ([]string, error) {
articleKey, err := ref.key(c)
if err != nil {
return nil, err
}
article := new(Article)
if err := datastore.Get(c, articleKey, article); err != nil && !IsFieldMismatch(err) {
return nil, err
}
article.Tags = tags
if _, err := datastore.Put(c, articleKey, article); err != nil {
return nil, err
}
var userKey *datastore.Key
if key, err := ref.UserID.key(c); err != nil {
return nil, err
} else {
userKey = key
}
batchWriter := NewBatchWriter(c, BatchPut)
for _, tagTitle := range tags {
tagKey := datastore.NewKey(c, "Tag", tagTitle, 0, userKey)
tag := Tag{}
if err := datastore.Get(c, tagKey, &tag); err == nil || IsFieldMismatch(err) {
// Already available
} else if err == datastore.ErrNoSuchEntity {
// Not yet available - add it
tag.Title = tagTitle
tag.Created = time.Now()
if err := batchWriter.Enqueue(tagKey, &tag); err != nil {
c.Errorf("Error queueing tag for batch write: %s", err)
return nil, err
}
} else {
// Some other error
return nil, err
}
}
if err := batchWriter.Flush(); err != nil {
c.Errorf("Error flushing batch queue: %s", err)
return nil, err
}
return article.Tags, nil
}