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

Golang datastore.GetMulti函数代码示例

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

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



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

示例1: ByIDs

// ByIDs filters out Tasks that are not visible to the current User.
func (s *TaskService) ByIDs(ctx context.Context, ids []string) ([]*Task, error) {
	span := trace.FromContext(ctx).NewChild("trythings.task.ByIDs")
	defer span.Finish()

	rootKey := datastore.NewKey(ctx, "Root", "root", 0, nil)

	ks := []*datastore.Key{}
	for _, id := range ids {
		ks = append(ks, datastore.NewKey(ctx, "Task", id, 0, rootKey))
	}

	var allTasks = make([]*Task, len(ks))
	err := datastore.GetMulti(ctx, ks, allTasks)
	if err != nil {
		return nil, err
	}

	ts := []*Task{}
	for _, t := range allTasks {
		// TODO#Perf: Batch the isVisible check.
		ok, err := s.IsVisible(ctx, t)
		if err != nil {
			return nil, err
		}
		if !ok {
			continue
		}

		ts = append(ts, t)
	}

	return ts, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:34,代码来源:task.go


示例2: resaveAllIdiomHistory

// 2015-11-06 to force field EditSummary (even if empty) on every IdiomHistory persisted entity.
func resaveAllIdiomHistory(c context.Context) error {
	defer memcache.Flush(c)
	saved := 0
	keys, err := datastore.NewQuery("IdiomHistory").KeysOnly().GetAll(c, nil)
	if err != nil {
		return err
	}
	nbEntities := len(keys)

	defer func() {
		log.Infof(c, "Resaved %d IdiomHistory entities out of %d.", saved, nbEntities)
	}()

	for len(keys) > 0 {
		bunch := 100
		if len(keys) < bunch {
			bunch = len(keys)
		}
		histories := make([]*IdiomHistory, bunch)
		err := datastore.GetMulti(c, keys[:bunch], histories)
		if err != nil {
			return err
		}
		_, err = datastore.PutMulti(c, keys[:bunch], histories)
		if err != nil {
			return err
		}
		saved += bunch

		// Remove processed keys
		keys = keys[bunch:]
	}
	return nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:35,代码来源:gaeDatastoreAdmin.go


示例3: GetMulti

// GetMulti wraps datastore.GetMulti
func (d *Driver) GetMulti(key []*datastore.Key, dst interface{}) error {
	var keyLen = len(key)
	var fromIdx, toIdx int
	var v = reflect.ValueOf(dst)
	// TODO: split multiple goroutine
	for {
		fromIdx = toIdx
		toIdx = fromIdx + 999
		if toIdx > keyLen {
			toIdx = keyLen
		}
		_keys := key[fromIdx:toIdx]
		_data := v.Slice(fromIdx, toIdx).Interface()
		d.logOps(opRead, len(_keys), "GetMulti")
		if err := datastore.GetMulti(d.ctx, _keys, _data); err != nil {
			return err
		}
		v1 := reflect.ValueOf(_data)
		for i := 0; i < toIdx-fromIdx; i++ {
			v.Index(fromIdx + i).Set(v1.Index(i))
		}
		if toIdx == keyLen {
			break
		}
	}
	return nil
}
开发者ID:speedland,项目名称:service,代码行数:28,代码来源:datastore.go


示例4: filterNextSessions

// filterNextSessions queries kindNext entities and returns a subset of items
// containing only the elements not present in the datastore, previously saved with
// storeNextSessions().
func filterNextSessions(c context.Context, items []*eventSession) ([]*eventSession, error) {
	pkey := nextSessionParent(c)
	keys := make([]*datastore.Key, len(items))
	for i, s := range items {
		id := s.ID + ":" + s.Update
		keys[i] = datastore.NewKey(c, kindNext, id, 0, pkey)
	}
	zeros := make([]struct{}, len(keys))
	err := datastore.GetMulti(c, keys, zeros)
	merr, ok := err.(appengine.MultiError)
	if !ok && err != nil {
		return nil, err
	}
	res := make([]*eventSession, 0, len(keys))
	for i, e := range merr {
		if e == nil {
			continue
		}
		if e != datastore.ErrNoSuchEntity {
			return nil, err
		}
		res = append(res, items[i])
	}
	return res, nil
}
开发者ID:CadeLaRen,项目名称:ioweb2016,代码行数:28,代码来源:db.go


示例5: averageResulter

func averageResulter(ctx context.Context, result model.KeyedResult, challenge model.Challenge) error {
	tasks := make([]model.Task, len(challenge.Tasks))
	if err := datastore.GetMulti(ctx, challenge.Tasks, tasks); err != nil {
		return err
	}

	var user model.User
	if err := datastore.Get(ctx, result.Key.Parent().Parent(), &user); err != nil {
		return err
	}

	var nrOfComputations float64
	average := model.Skills{}

	for i, task := range tasks {
		taskResult, err := Tasker(task.Tasker).Call(ctx, result, *task.Key(challenge.Tasks[i]), user, result.StartTimes[getTaskIndex(challenge, challenge.Tasks[i])])
		if err != nil {
			// TODO: ignore error for now. We`ll treat it after we have all the taskers available
			//return err
		} else {
			average = average.Add(taskResult)
			nrOfComputations++
		}
	}

	result.Skills = average.DivBy(nrOfComputations)
	result.Computed = time.Now()

	_, err := result.Put(ctx, result.Key)
	return err
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:31,代码来源:resulter_average.go


示例6: LoadMagazines

func (s *Store) LoadMagazines(keys []*datastore.Key, a []*Magazine) error {
	if err := datastore.GetMulti(s.c, keys, a); err != nil {
		return err
	}
	for _, m := range a {
		m.Init(s.c)
	}
	return nil
}
开发者ID:lufia,项目名称:magazine,代码行数:9,代码来源:store.go


示例7: LoadUsers

func (s *Store) LoadUsers(keys []*datastore.Key, a []*User) error {
	if err := datastore.GetMulti(s.c, keys, a); err != nil {
		return err
	}
	for _, u := range a {
		u.Init(s.c)
	}
	return nil
}
开发者ID:lufia,项目名称:magazine,代码行数:9,代码来源:store.go


示例8: GetMulti

func (d rdsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetMultiCB) error {
	rkeys := dsMF2R(keys)
	vals := make([]datastore.PropertyLoadSaver, len(keys))
	for i := range keys {
		vals[i] = &typeFilter{ds.PropertyMap{}}
	}
	err := datastore.GetMulti(d, rkeys, vals)
	return idxCallbacker(err, len(keys), func(idx int, err error) {
		cb(vals[idx].(*typeFilter).pm, err)
	})
}
开发者ID:martiniss,项目名称:gae,代码行数:11,代码来源:raw_datastore.go


示例9: example

func example() {
	// [START batch]
	// A batch put.
	_, err = datastore.PutMulti(ctx, []*datastore.Key{k1, k2, k3}, []interface{}{e1, e2, e3})

	// A batch get.
	var entities = make([]*T, 3)
	err = datastore.GetMulti(ctx, []*datastore.Key{k1, k2, k3}, entities)

	// A batch delete.
	err = datastore.DeleteMulti(ctx, []*datastore.Key{k1, k2, k3})
	// [END batch]
	_ = err
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:14,代码来源:entities.go


示例10: GetChallengesForProfile

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

	_, ok := passenger.FromContext(ctx)
	if !ok {
		return http.StatusUnauthorized, nil
	}

	var profileKey *datastore.Key
	if profileKey, err = datastore.DecodeKey(mux.Vars(r)["key"]); err != nil {
		return http.StatusInternalServerError, err
	}

	q := model.NewQueryForResult().
		Ancestor(profileKey)
	if finished := r.URL.Query()["finished"]; len(finished) > 0 && finished[0] == "true" {
		q = q.Filter("Finished >", time.Time{})
	}
	if order := r.URL.Query()["order"]; len(order) > 0 && order[0] != "" {
		q = q.Order(order[0])
	}

	if limitQuery := r.URL.Query()["limit"]; len(limitQuery) > 0 {
		if limit, err := strconv.Atoi(limitQuery[0]); err != nil {
			return http.StatusInternalServerError, err
		} else {
			q = q.Limit(limit)
		}
	}

	var results model.Results
	if _, err = q.GetAll(ctx, &results); err != nil {
		return http.StatusInternalServerError, err
	}

	challengeKeys := make([]*datastore.Key, len(results))
	for i, val := range results {
		challengeKeys[i] = val.Challenge
	}

	challenges := make(model.Challenges, len(challengeKeys))
	if err = datastore.GetMulti(ctx, challengeKeys, challenges); err != nil {
		return http.StatusInternalServerError, err
	}

	json.NewEncoder(w).Encode(challenges.Key(challengeKeys))
	return
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:50,代码来源:profile.go


示例11: GetMulti

func (d rdsImpl) GetMulti(keys []*ds.Key, _meta ds.MultiMetaGetter, cb ds.GetMultiCB) error {
	vals := make([]datastore.PropertyLoadSaver, len(keys))
	rkeys, err := dsMF2R(d.aeCtx, keys)
	if err == nil {
		for i := range keys {
			vals[i] = &typeFilter{d.aeCtx, ds.PropertyMap{}}
		}
		err = datastore.GetMulti(d.aeCtx, rkeys, vals)
	}
	return idxCallbacker(err, len(keys), func(idx int, err error) {
		if pls := vals[idx]; pls != nil {
			cb(pls.(*typeFilter).pm, err)
		} else {
			cb(nil, err)
		}
	})
}
开发者ID:tetrafolium,项目名称:gae,代码行数:17,代码来源:raw_datastore.go


示例12: Load

// Load reads the JSON representation of entities from the io.Reader "r",
// and stores them in the Datastore using the given context.Context.
// The Options parameter allows you to configure how the dump will work.
// If there is any parsing erros, improper format, or datastore failures
// during the process, that error is returned and processing stops. The
// error may be returned after some entities were loaded: there is no
// parsing cache.
func Load(c context.Context, r io.Reader, o *Options) error {
	entities, err := DecodeEntities(c, r)
	if err != nil {
		return err
	}
	if len(entities) == 0 {
		log.Infof(c, "Skipping load of 0 entities")
		return nil
	}
	batchSize := o.BatchSize
	if batchSize <= 0 {
		batchSize = 50
	}
	for start, end := 0, 0; start < len(entities); {
		end += batchSize
		if end > len(entities) {
			end = len(entities)
		}
		keys := make([]*datastore.Key, 0, end-start)
		values := make([]datastore.PropertyList, 0, cap(keys))

		for _, e := range entities[start:end] {
			keys = append(keys, e.Key)
			values = append(values, e.Properties)
		}

		keys, err = datastore.PutMulti(c, keys, values)
		if err != nil {
			return err
		}
		log.Infof(c, "Loaded %d entities ...", len(keys))

		if o.GetAfterPut {
			log.Infof(c, "Making a read to force consistency ...")
			l := make([]Entity, len(keys))
			err := datastore.GetMulti(c, keys, l)
			if err != nil {
				return err
			}
		}

		start = end
	}

	return nil
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:53,代码来源:funcs.go


示例13: adminMarkPaid

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

	action := r.FormValue("action")

	keys := make([]*datastore.Key, 0, len(r.Form["pay"]))
	for _, s := range r.Form["pay"] {
		k, err := datastore.DecodeKey(s)
		if err != nil {
			panic(err)
		}
		keys = append(keys, k)
	}

	if action == "Mark Paid" {
		tasks := make([]LoggedTask, len(keys))

		err := datastore.GetMulti(c, keys, tasks)
		if err != nil {
			panic(err)
		}

		now := time.Now().UTC()
		for i := range tasks {
			tasks[i].Paid = true
			tasks[i].PaidTime = now
		}

		_, err = datastore.PutMulti(c, keys, tasks)
		if err != nil {
			panic(err)
		}
	} else if action == "Delete" {
		err := datastore.DeleteMulti(c, keys)
		if err != nil {
			panic(err)
		}
	} else {
		panic("Unhandled action: " + action)
	}

	http.Redirect(w, r, "/admin/", 303)
}
开发者ID:dustin,项目名称:sallingshome,代码行数:43,代码来源:admin.go


示例14: executeIdiomTextSearchQuery

func executeIdiomTextSearchQuery(c context.Context, query string, limit int) ([]*Idiom, error) {
	// log.Infof(c, query)
	index, err := gaesearch.Open("idioms")
	if err != nil {
		return nil, err
	}
	if limit == 0 {
		// Limit is not optional. 0 means zero result.
		return nil, nil
	}
	idiomKeys := make([]*datastore.Key, 0, limit)
	// This is an *IDsOnly* search, where docID == Idiom.Id
	it := index.Search(c, query, &gaesearch.SearchOptions{
		Limit:   limit,
		IDsOnly: true,
	})
	for {
		docID, err := it.Next(nil)
		if err == gaesearch.Done {
			break
		}
		if err != nil {
			return nil, err
		}
		idiomID, err := strconv.Atoi(docID)
		if err != nil {
			return nil, err
		}
		key := newIdiomKey(c, idiomID)
		idiomKeys = append(idiomKeys, key)
	}
	// Fetch Idioms in a []Idiom
	buffer := make([]Idiom, len(idiomKeys))
	err = datastore.GetMulti(c, idiomKeys, buffer)
	// Convert []Idiom to []*Idiom
	idioms := make([]*Idiom, len(buffer))
	for i := range buffer {
		// Do not take the address of the 2nd range variable, it would make a copy.
		// Better take the address in the existing buffer.
		idioms[i] = &buffer[i]
	}
	return idioms, err
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:43,代码来源:dataAccessorGaeSearch.go


示例15: NextWithErr

func (iter *LongBatchingIterator) NextWithErr() (*types.Complaint, error) {
	if iter.err != nil {
		return nil, iter.err
	}

	if len(iter.vals) == 0 && len(iter.keys) == 0 {
		return nil, nil // We're all done !
	}

	// No new vals left in the cache; fetch some
	if len(iter.vals) == 0 {
		var keysForThisBatch []*datastore.Key

		if len(iter.keys) < iter.BatchSize {
			// Remaining keys not enough for a full page; grab all of 'em
			keysForThisBatch = iter.keys
			iter.keys = []*datastore.Key{}
		} else {
			keysForThisBatch = iter.keys[0:iter.BatchSize]
			iter.keys = iter.keys[iter.BatchSize:]
		}

		// Fetch the complaints for the keys in this batch
		complaints := make([]types.Complaint, len(keysForThisBatch))
		if err := datastore.GetMulti(iter.Ctx, keysForThisBatch, complaints); err != nil {
			iter.err = err
			return nil, err
		}

		iter.vals = make([]*types.Complaint, len(keysForThisBatch))
		for i, _ := range complaints {
			FixupComplaint(&complaints[i], keysForThisBatch[i])
			iter.vals[i] = &complaints[i]
		}
	}

	// We have unreturned results in the cache; shift & return it
	complaint := iter.vals[0]
	iter.vals = iter.vals[1:]

	return complaint, nil
}
开发者ID:skypies,项目名称:complaints,代码行数:42,代码来源:longbatchingiterator.go


示例16: init

func init() {
	RegisterResulter(Average, func(ctx context.Context, resultKey *datastore.Key) error {
		var result model.Result
		if err := datastore.Get(ctx, resultKey, &result); err != nil {
			return err
		}

		var challenge model.Challenge
		if err := datastore.Get(ctx, result.Challenge, &challenge); err != nil {
			return err
		}

		var tasks model.Tasks
		if err := datastore.GetMulti(ctx, challenge.Tasks, &tasks); err != nil {
			return err
		}

		weightSum := model.Skills{} // this could be SkillWeights, but would need more conversions
		average := model.Skills{}

		for i, task := range tasks {
			taskResult, err := Tasker(task.Tasker).Call(ctx, challenge.Tasks[i], resultKey.Parent().Parent())
			if err != nil {
				return err
			}
			average = average.Add(taskResult.Mul(model.Skills(task.SkillWeights)))
			weightSum = weightSum.Add(model.Skills(task.SkillWeights))
		}

		result.Skills = average.Div(weightSum)
		result.Computed = time.Now()

		_, err := result.Put(ctx, resultKey)
		return err
	})
}
开发者ID:pbochis,项目名称:api,代码行数:36,代码来源:logic.go


示例17: createSampleEntities

func createSampleEntities(c context.Context, size int) error {
	buff := make([]Entity, 0, 10)
	keys := make([]*datastore.Key, 0, 10)
	for i := 1; i <= size; i++ {
		k := datastore.NewKey(c, "User", "", int64(i), nil)
		e := Entity{Key: k}
		e.Add(datastore.Property{Name: "Title", Value: lorem.Sentence(5, 10)})
		e.Add(datastore.Property{
			Name:    "SubTitle",
			Value:   lorem.Sentence(3, 5),
			NoIndex: true,
		})
		e.Add(datastore.Property{
			Name:    "Description",
			Value:   lorem.Paragraph(3, 5),
			NoIndex: true,
		})
		e.Add(datastore.Property{Name: "Size", Value: int64(32)})
		for j := 0; j < 5; j++ {
			e.Add(datastore.Property{
				Name:     "Tags",
				Value:    lorem.Word(5, 10),
				Multiple: true,
			})
		}
		e.Add(datastore.Property{Name: "Price", Value: float64(123.45)})
		for j := 0; j < 10; j++ {
			e.Add(datastore.Property{
				Name:     "PriceHistory",
				Value:    float64(123.45) - float64(j),
				Multiple: true,
			})
		}
		e.Add(datastore.Property{Name: "Favicon", Value: icon, NoIndex: true})
		e.Add(datastore.Property{Name: "FaviconSource", Value: blobKey})
		for j := 1; j <= 3; j++ {
			e.Add(datastore.Property{
				Name:     "Friends",
				Value:    datastore.NewKey(c, "Friend", "", int64(j), k),
				Multiple: true,
			})
		}
		buff = append(buff, e)
		keys = append(keys, k)

		if len(buff) == 10 {
			_, err := datastore.PutMulti(c, keys, buff)
			if err != nil {
				return err
			}
			_ = datastore.GetMulti(c, keys, buff)

			buff = make([]Entity, 0, 10)
			keys = make([]*datastore.Key, 0, 10)
		}
	}
	if len(buff) > 0 {
		k, err := datastore.PutMulti(c, keys, buff)
		if err != nil {
			return err
		}
		_ = datastore.GetMulti(c, k, buff)
	}
	return nil
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:65,代码来源:funcs_test.go


示例18: getMulti

// GetMulti officially supports less 1000 keys per a call.
// internal func split keys to support +1000
func (d *Driver) getMulti(key []*datastore.Key, dst interface{}) error {
	d.logOps(opRead, len(key), "GetMulti")
	return datastore.GetMulti(d.ctx, key, dst)
}
开发者ID:speedland,项目名称:service,代码行数:6,代码来源:datastore.go


示例19: searchIdiomsByWordsWithFavorites


//.........这里部分代码省略.........
		// 1) Impls in lang, containing all words
		implRetriever := func() ([]string, error) {
			var keystrings []string
			implQuery := "Bulk:(~" + strings.Join(terms, " AND ~") + ") AND Lang:" + lang
			implIdiomIDs, _, err := executeImplTextSearchQuery(c, implQuery, limit)
			if err != nil {
				return nil, err
			}
			for _, idiomID := range implIdiomIDs {
				idiomKey := newIdiomKey(c, idiomID)
				idiomKeyString := idiomKey.Encode()
				keystrings = append(keystrings, idiomKeyString)
			}
			return keystrings, nil
		}
		retrievers = []retriever{
			// 1) Idioms with words in title, having an impl in lang
			idiomQueryRetriever("TitleWords:(~" + strings.Join(typedWords, " AND ~") + ") AND Langs:(" + lang + ")"),
			// 2) Implementations in lang, containing all terms
			implRetriever,
			// 3) Idioms with words in lead paragraph (or title), having an impl in lang
			idiomQueryRetriever("TitleOrLeadWords:(~" + strings.Join(typedWords, " AND ~") + ") AND Langs:(" + lang + ")"),
			// 4) Just all the terms
			idiomQueryRetriever("Bulk:(~" + strings.Join(terms, " AND ~") + ")"),
		}

	} else {
		// Either 0 or many langs. Just make sure all terms are respected.
		retrievers = append(retrievers,
			// 1) Words in idiom title, having all the langs implemented
			idiomQueryRetriever("TitleWords:(~"+strings.Join(typedWords, " AND ~")+") AND Bulk:(~"+strings.Join(terms, " AND ~")+")"),
			// 2) Words in idiom lead paragraph (or title), having all the langs implemented
			idiomQueryRetriever("TitleOrLeadWords:(~"+strings.Join(typedWords, " AND ~")+") AND Bulk:(~"+strings.Join(terms, " AND ~")+")"),
			// 3) Terms (words and langs) somewhere in idiom
			idiomQueryRetriever("Bulk:(~"+strings.Join(terms, " AND ~")+")"),
		)
	}

	// Each retriever will send 1 slice in 1 channel. So we can harvest them in right order.
	promises := make([]chan []string, len(retrievers))
	for i := range retrievers {
		retriever := retrievers[i]
		promises[i] = make(chan []string, 1)
		ch := promises[i]
		go func() {
			keyStrings, err := retriever()
			if err != nil {
				log.Errorf(c, "problem fetching search results: %v", err)
				ch <- nil
			} else {
				ch <- keyStrings
			}
			close(ch)
		}()
	}
harvestloop:
	for _, promise := range promises {
		kstrChunk := <-promise
		m := 0
		dupes := 0
		for _, kstr := range kstrChunk {
			if seenIdiomKeyStrings[kstr] {
				dupes++
			} else {
				m++
				idiomKeyStrings = append(idiomKeyStrings, kstr)
				seenIdiomKeyStrings[kstr] = true
				if len(idiomKeyStrings) == limit {
					log.Debugf(c, "%d new results, %d dupes, stopping here.", m, dupes)
					break harvestloop
				}
			}
		}
		log.Debugf(c, "%d new results, %d dupes.", m, dupes)
	}

	// TODO use favoriteLangs
	// TODO use seeNonFavorite (or not)

	var err error
	idiomKeys := make([]*datastore.Key, len(idiomKeyStrings))
	for i, kstr := range idiomKeyStrings {
		idiomKeys[i], err = datastore.DecodeKey(kstr)
		if err != nil {
			return nil, err
		}
	}

	// Fetch Idioms in a []Idiom
	buffer := make([]Idiom, len(idiomKeys))
	err = datastore.GetMulti(c, idiomKeys, buffer)
	// Convert []Idiom to []*Idiom
	idioms := make([]*Idiom, len(buffer))
	for i := range buffer {
		// Do not take the address of the 2nd range variable, it would make a copy.
		// Better take the address in the existing buffer.
		idioms[i] = &buffer[i]
	}
	return idioms, err
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:101,代码来源:dataAccessorGaeSearch.go


示例20: serveComplete

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

	u := user.Current(c)
	su, err := getUser(c, u)
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "You are not permitted, %v", u)
		return
	}

	if err := r.ParseForm(); err != nil {
		http.Error(w, err.Error(), 400)
		fmt.Fprintf(w, "Can't parse form from %v", u)
		return
	}

	taskIds := []*datastore.Key{}
	for _, s := range r.Form["task"] {
		k, err := datastore.DecodeKey(s)
		if err != nil {
			panic(err)
		}
		taskIds = append(taskIds, k)
	}

	log.Infof(c, "Doing tasks for %v:  %v", su, taskIds)

	tasks := make([]Task, len(taskIds))
	err = datastore.GetMulti(c, taskIds, tasks)
	if err != nil {
		panic(err)
	}

	now := time.Now()
	storeKeys := make([]*datastore.Key, 0, 2*len(taskIds))
	vals := []interface{}{}
	for i := range tasks {
		if tasks[i].Next.Before(now) {
			tasks[i].updateTime()
			tasks[i].Prev = now
			storeKeys = append(storeKeys, taskIds[i])

			vals = append(vals, &tasks[i])

			storeKeys = append(storeKeys,
				datastore.NewIncompleteKey(c, "LoggedTask", nil))
			vals = append(vals, &LoggedTask{
				Task:      taskIds[i],
				User:      su.Key,
				Completed: now,
				Who:       su.Name,
				Name:      tasks[i].Name,
				Amount:    tasks[i].Value,
			})
		}
	}

	log.Infof(c, "Putting %#v in %v", vals, storeKeys)

	_, err = datastore.PutMulti(c, storeKeys, vals)
	if err != nil {
		http.Error(w, err.Error(), 500)
		log.Errorf(c, "Error saving stuff: %v", err)
		return
	}

	http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}
开发者ID:dustin,项目名称:sallingshome,代码行数:69,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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