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

Golang datastore.NewIncompleteKey函数代码示例

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

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



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

示例1: put

func put(rw http.ResponseWriter, req *http.Request) {
	c := appengine.NewContext(req)
	u := user.Current(c)
	m := req.FormValue("message")
	s := req.FormValue("encoded_key")
	// fmt.Fprintf(rw, "Key 1: %v", s)
	p := req.FormValue("parent_key")
	var t, ut string
	var op bool
	var k *datastore.Key

	// make/decode keys
	if s == "" {
		if p == "" {
			k = datastore.NewIncompleteKey(c, "post", nil)
			op = true
		} else {
			pk, err := datastore.DecodeKey(p)
			if err != nil {
				http.Error(rw, err.Error(), http.StatusInternalServerError)
				return
			}
			k = datastore.NewIncompleteKey(c, "post", pk)
			op = false
		}
		t = time.Now().Format("Jan 2, 2006 3:04 PM")
		ut = ""
	} else {
		k, err := datastore.DecodeKey(s)
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}
		mypost := Post{}
		err = datastore.Get(c, k, &mypost)
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}
		ut = time.Now().Format("Jan 2, 2006 3:04 PM")
		t = mypost.PostDate
		op = mypost.OP
	}

	// data := url.Values{}
	// data.Set("encoded_key", k.Encode())

	// r, _ := http.NewRequest("POST", "/view", bytes.NewBufferString(data.Encode()))

	newpost := Post{Author: u.String(), Message: m, UpdateDate: ut, PostDate: t, OP: op}
	_, err := datastore.Put(c, k, &newpost)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
	// http.Redirect(rw, r, "/view", http.StatusOK)
	http.Redirect(rw, req, "/", http.StatusTemporaryRedirect)
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:58,代码来源:BulletinBoard.go


示例2: SaveBoardState

// SaveBoardState commits the state to the datastore
func SaveBoardState(c context.Context, state *BoardState) (*BoardState, error) {
	sessionKey, err := datastore.DecodeKey(state.SessionID)
	if err != nil {
		return nil, err
	}
	stateModel := &boardStateModel{}
	stateModel.parentKey = sessionKey
	stateModel.lastModified = time.Now()
	stateModel.key, err = datastore.Put(c, datastore.NewIncompleteKey(c, "BoardState", stateModel.parentKey), stateModel)
	if err != nil {
		return nil, err
	}

	// Initialize the result
	result := &BoardState{
		ID:           stateModel.key.Encode(),
		SessionID:    stateModel.parentKey.Encode(),
		LastModified: time.Now(),
		Players:      make(map[string]*Player),
	}

	// Save the players
	for k, v := range state.Players {
		p := &playerModel{
			Name:     k,
			Location: v.Location,
		}
		p.parentKey = stateModel.key
		p.key, err = datastore.Put(c, datastore.NewIncompleteKey(c, "PlayerState", p.parentKey), p)
		if err != nil {
			return nil, err
		}

		for _, card := range v.Hand {
			cardModel := &cardModel{
				Name:  card.Name,
				Color: card.Color,
			}
			cardModel.parentKey = p.key
			cardModel.key, err = datastore.Put(c, datastore.NewIncompleteKey(c, "PlayerCard", p.parentKey), cardModel)
			if err != nil {
				return nil, err
			}

		}

		// Added player to result
		result.Players[k] = &Player{
			Location: p.Location,
			Hand:     v.Hand,
		}
	}

	return result, nil
}
开发者ID:jward6,项目名称:gopandemus,代码行数:56,代码来源:datastore.go


示例3: example6

func example6() {
	// [START parent]
	// Create Employee entity
	employee := &Employee{ /* ... */ }
	employeeKey, err := datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Employee", nil), employee)

	// Use Employee as Address entity's parent
	// and save Address entity to datastore
	address := &Address{ /* ... */ }
	addressKey := datastore.NewIncompleteKey(ctx, "Address", employeeKey)
	_, err = datastore.Put(ctx, addressKey, address)
	// [END parent]
	_ = err
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:14,代码来源:entities.go


示例4: insert

// POST http://localhost:8080/profiles
// {"first_name": "Ivan", "nick_name": "Socks", "last_name": "Hawkes"}
//
func (u *ProfileApi) insert(r *restful.Request, w *restful.Response) {
	c := appengine.NewContext(r.Request)

	// Marshall the entity from the request into a struct.
	p := new(Profile)
	err := r.ReadEntity(&p)
	if err != nil {
		w.WriteError(http.StatusNotAcceptable, err)
		return
	}

	// Ensure we start with a sensible value for this field.
	p.LastModified = time.Now()

	// The profile belongs to this user.
	p.Email = user.Current(c).String()

	k, err := datastore.Put(c, datastore.NewIncompleteKey(c, "profiles", nil), p)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Let them know the location of the newly created resource.
	// TODO: Use a safe Url path append function.
	w.AddHeader("Location", u.Path+"/"+k.Encode())

	// Return the resultant entity.
	w.WriteHeader(http.StatusCreated)
	w.WriteEntity(p)
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:34,代码来源:main.go


示例5: writeLinkTweet

//WriteLinkTweet writes a given Tweet to the datastore
func (mb MapBuilder) writeLinkTweet(tweets <-chan anaconda.Tweet, wg *sync.WaitGroup) {
	defer wg.Done()

	var keys []*datastore.Key
	var values []*int64

	for tweet := range tweets {
		key := datastore.NewIncompleteKey(mb.c, linkTweetKind, getTweetKey(mb.c))
		keys = append(keys, key)
		values = append(values, &tweet.Id)
	}

	err := datastore.RunInTransaction(mb.c, func(c context.Context) error {
		_, err := datastore.PutMulti(c, keys, values)

		if err != nil {
			log.Errorf(c, "Failed to write LinkTweet to datastore. %v", err.Error())
			return err
		}
		return nil
	}, nil)
	if err != nil {
		log.Errorf(mb.c, "Failed to write LinkTweet to datastore. %v", err.Error())
	}
}
开发者ID:AndyNortrup,项目名称:TweetHarvest,代码行数:26,代码来源:map-builder.go


示例6: APIKeyAddHandler

func APIKeyAddHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		loginUrl, _ := user.LoginURL(c, r.URL.RequestURI())
		http.Redirect(w, r, loginUrl, http.StatusFound)
		return
	} else {
		if !u.Admin {
			w.WriteHeader(http.StatusForbidden)
			w.Write([]byte("You're not an admin. Go away."))
		} else {
			key := randomString(26)
			owner := r.FormValue("owner")

			if owner == "" {
				w.Write([]byte("You forgot a parameter."))
			} else {
				apiKey := APIKey{
					APIKey:     key,
					OwnerEmail: owner,
				}
				dkey := datastore.NewIncompleteKey(c, "APIKey", nil)
				_, err := datastore.Put(c, dkey, &apiKey)
				if err != nil {
					w.Write([]byte(fmt.Sprintf("error! %s", err.Error())))
				} else {
					w.Write([]byte(key))

				}
			}
		}
	}
}
开发者ID:jordonwii,项目名称:hms,代码行数:34,代码来源:hms.go


示例7: warmupHandler

func warmupHandler(c *echo.Context) error {
	if appengine.IsDevAppServer() {
		photographers := []Photographer{
			{1, "Mr Canon"},
			{2, "Miss Nikon"},
			{3, "Mrs Pentax"},
			{4, "Ms Sony"},
		}

		// create some dummy data
		for m := 1; m <= 12; m++ {
			for d := 1; d < 28; d++ {
				taken := time.Date(2015, time.Month(m), d, 12, 0, 0, 0, time.UTC)
				id := rand.Int31n(4)
				photographer := photographers[id]
				p := Photo{
					Photographer: photographer,
					Uploaded:     time.Now().UTC(),
					Width:        8000,
					Height:       6000,
					Taken:        taken,
				}
				k := datastore.NewIncompleteKey(c, "photo", nil)
				nds.Put(c, k, &p)
			}
		}
	}
	return c.NoContent(http.StatusOK)
}
开发者ID:komasoftware,项目名称:go-appengine-mapper,代码行数:29,代码来源:warmup.go


示例8: getOrCreateChat

func getOrCreateChat(c context.Context, fbChatID int64, keyBuf **datastore.Key) (*Chat, error) {
	results := make([]Chat, 0, 1)
	keys, err := datastore.NewQuery("Chat").
		Filter("FacebookChatID =", fbChatID).Limit(1).GetAll(c, &results)
	if err != nil {
		return nil, err
	}

	var resultChat *Chat
	var resultKey *datastore.Key

	if len(keys) == 0 {
		incKey := datastore.NewIncompleteKey(c, "Chat", nil)
		resultChat = &Chat{
			FacebookChatID: fbChatID,
			ChatName:       "",
		}
		resultKey, err = datastore.Put(c, incKey, resultChat)
		if err != nil {
			return nil, err
		}
	} else {
		resultKey = keys[0]
		resultChat = &results[0]
	}

	if keyBuf != nil {
		*keyBuf = resultKey
	}

	return resultChat, nil
}
开发者ID:jordonwii,项目名称:hms,代码行数:32,代码来源:models.go


示例9: CreateVenueHandler

// CreateVenueHandler makes a new venue and saves it to the datastore
func CreateVenueHandler(w util.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	var venueData Venue
	if err := json.NewDecoder(r.Body).Decode(&venueData); err != nil {
		log.Println("Unable to decode create venue data:", err.Error())
		http.Error(w, "Unable to decode JSON request body", http.StatusBadRequest)
		return
	}

	if venueData.Name == "" {
		http.Error(w, `must provide "name" field when creating a venue`, http.StatusBadRequest)
		return
	}

	key := datastore.NewIncompleteKey(c, "Venues", nil)
	newKey, err := datastore.Put(c, key, &venueData)
	if err != nil {
		w.WriteJSON(nil, err)
		return
	}

	venueData.ID = newKey.IntID()
	w.WriteJSON(&venueData, nil)
}
开发者ID:tgrosinger,项目名称:mac-and-cheese,代码行数:26,代码来源:venue.go


示例10: generateRandom

// this will generate some random data for the given day
// 24 * 12 on appengine (288)
// 24 only on development
func generateRandom(c context.Context, day time.Time) error {
	var x int
	if appengine.IsDevAppServer() {
		x = 1
	} else {
		x = 12
	}
	keys := make([]*datastore.Key, 24*x)
	photos := make([]*Photo, 24*x)

	id := 0
	for h := 0; h < 24; h++ {
		taken := day.Add(time.Duration(h) * time.Hour)
		for i := 0; i < x; i++ {
			photographer := photographers[rand.Int31n(4)]
			photos[id] = &Photo{
				Photographer: photographer,
				Uploaded:     time.Now().UTC(),
				Width:        8000,
				Height:       6000,
				Taken:        taken,
				TakenDay:     day,
			}
			keys[id] = datastore.NewIncompleteKey(c, "photo", nil)
			id++
		}
	}
	nds.PutMulti(c, keys, photos)
	return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:33,代码来源:warmup.go


示例11:

// Put will put this Submission into Datastore using the given key.
func (ƨ Submission) Put(ctx context.Context, key *datastore.Key) (*datastore.Key, error) {
	if key != nil {
		return datastore.Put(ctx, key, &ƨ)
	}

	return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Submission", nil), &ƨ)
}
开发者ID:pbochis,项目名称:api,代码行数:8,代码来源:submission_impl.go


示例12: adminNewTask

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

	asInt := func(s string) int {
		i, err := strconv.Atoi(s)
		if err != nil {
			panic(err)
		}
		return i
	}

	task := Task{
		Name:        r.FormValue("name"),
		Description: r.FormValue("description"),
		Assignee:    r.FormValue("assignee"),
		RType:       r.FormValue("rtype"),
		Automatic:   mightParseBool(r.FormValue("automatic")),
		Period:      asInt(r.FormValue("period")),
		Value:       asInt(r.FormValue("value")),
		Next:        time.Now().UTC(),
	}

	k, err := datastore.Put(c,
		datastore.NewIncompleteKey(c, "Task", nil), &task)
	if err != nil {
		log.Warningf(c, "Error storing task:  %v", err)
		panic(err)
	}
	log.Infof(c, "Stored new thing with key %v", k)

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


示例13: putTweet

// insert tweet
func putTweet(req *http.Request, tweet *Tweet) error {
	ctx := appengine.NewContext(req)
	key := datastore.NewIncompleteKey(ctx, "Tweet", nil)
	_, err := datastore.Put(ctx, key, tweet)
	return err
	// you can use memcache also to improve your consistency
}
开发者ID:nick11roberts,项目名称:SummerBootCamp,代码行数:8,代码来源:data.go


示例14: create2Handler

func create2Handler(w http.ResponseWriter, r *http.Request) {
	strTitle := r.FormValue("title")
	strLink := r.FormValue("link")
	//	fmt.Fprint(w, "go title: ", strTitle)
	//	fmt.Fprint(w, "link: ", strLink)

	//TODO error checking for the title and link

	c := appengine.NewContext(r)
	u := user.Current(c)

	//TODO error checking for user?

	//TODO check random thread against an already existing one
	rand.Seed(time.Now().UnixNano())
	newThreadId := rand.Int63()

	newSubmission := WebSubmission{
		Title:          strTitle,
		Link:           strLink,
		SubmitBy:       u.String(),
		Thread:         newThreadId, //TODO create random thread id
		SubmitDateTime: time.Now(),
		SubmissionDesc: "",
		Score:          0,
	}

	_, err := datastore.Put(c, datastore.NewIncompleteKey(c, WebSubmissionEntityName, nil), &newSubmission)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

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


示例15:

// Put will put this JunitTestResult into Datastore using the given key.
func (ƨ JunitTestResult) Put(ctx context.Context, key *datastore.Key) (*datastore.Key, error) {
	if key != nil {
		return datastore.Put(ctx, key, &ƨ)
	}

	return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "JunitTestResult", nil), &ƨ)
}
开发者ID:pbochis,项目名称:api,代码行数:8,代码来源:junit_test_result_impl.go


示例16: submitAddHandler

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

	success, err := recaptchaCheck(ctx, r.FormValue("g-recaptcha-response"), r.RemoteAddr)
	if err != nil {
		serveErr(ctx, err, w)
		return
	}

	if !success {
		log.Warningf(ctx, "reCAPTCHA check failed")
		failedTmpl.ExecuteTemplate(w, "base", nil)
		return
	}

	sub := Submission{
		URL:       template.URL(strings.TrimSpace(r.FormValue("url"))),
		Submitted: time.Now(),
	}

	if _, err := datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Submission", nil), &sub); err != nil {
		serveErr(ctx, err, w)
		return
	}

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


示例17: CreateVenueDishHandler

// CreateVenueDishHandler creates a new dish based on the request body
func CreateVenueDishHandler(w util.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	var dishData Dish
	if err := json.NewDecoder(r.Body).Decode(&dishData); err != nil {
		log.Println("Unable to decode create dish data:", err.Error())
		http.Error(w, "Unable to decode JSON request body", http.StatusBadRequest)
		return
	}

	venueID, err := util.GetIntParam(r, "venue_id", 0)
	if !VenueExists(c, venueID) {
		http.Error(w, "provided venue_id does not exist", http.StatusBadRequest)
		return
	}
	dishData.VenueID = venueID

	if dishData.Name == "" {
		http.Error(w, `must provide "name" field when creating a dish`, http.StatusBadRequest)
		return
	}

	key := datastore.NewIncompleteKey(c, "Dishes", nil)
	newKey, err := datastore.Put(c, key, &dishData)
	if err != nil {
		w.WriteJSON(nil, err)
		return
	}

	dishData.ID = newKey.IntID()
	w.WriteJSON(&dishData, nil)
}
开发者ID:tgrosinger,项目名称:mac-and-cheese,代码行数:33,代码来源:dish.go


示例18: key

func (t *Todo) key(c context.Context) *datastore.Key {
	if t.Id == 0 {
		t.Created = time.Now()
		return datastore.NewIncompleteKey(c, "Todo", DefaultTodoList(c))
	}
	return datastore.NewKey(c, "Todo", "", t.Id, DefaultTodoList(c))
}
开发者ID:lamproae,项目名称:beegae,代码行数:7,代码来源:todo.go


示例19: putTweet

func putTweet(req *http.Request, user *User, tweet *Tweet) error {
	ctx := appengine.NewContext(req)
	userKey := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	key := datastore.NewIncompleteKey(ctx, "Tweets", userKey)
	_, err := datastore.Put(ctx, key, tweet)
	return err
}
开发者ID:RobertoSuarez,项目名称:GolangTraining,代码行数:7,代码来源:tweets.go


示例20: run

func (s *MigrationService) run(ctx context.Context, m *Migration) error {
	if m.RunAt.IsZero() {
		m.RunAt = time.Now()
	}

	if m.Version.IsZero() {
		return errors.New("cannot run migration without version")
	}

	// TODO: Pipe rootKey through with context.
	rootKey := datastore.NewKey(ctx, "Root", "root", 0, nil)
	k := datastore.NewIncompleteKey(ctx, "Migration", rootKey)

	err := m.Run(ctx, s)
	if err != nil {
		return err
	}

	_, err = datastore.Put(ctx, k, m)
	if err != nil {
		return err
	}

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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