當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Goon.Put方法代碼示例

本文整理匯總了Golang中github.com/mjibson/goon.Goon.Put方法的典型用法代碼示例。如果您正苦於以下問題:Golang Goon.Put方法的具體用法?Golang Goon.Put怎麽用?Golang Goon.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mjibson/goon.Goon的用法示例。


在下文中一共展示了Goon.Put方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TokenGet

func TokenGet(c context.Context, w http.ResponseWriter, r *http.Request, u *User, g *goon.Goon) (interface{}, error) {
	if !validCSRF(r.FormValue("csrf"), u) {
		return nil, errCSRF
	}
	redir, err := url.Parse(r.FormValue("redirect"))
	if err != nil {
		return nil, err
	}
	uk, err := g.KeyError(u)
	if err != nil {
		return nil, err
	}
	b := make([]byte, 64)
	if _, err := rand.Read(b); err != nil {
		return nil, err
	}
	token := &Token{
		ID:     base64.URLEncoding.EncodeToString(b),
		User:   uk,
		Name:   r.FormValue("hostname"),
		Issued: time.Now(),
	}
	if _, err := g.Put(token); err != nil {
		return nil, err
	}
	values := redir.Query()
	values.Add("token", token.ID)
	redir.RawQuery = values.Encode()
	http.Redirect(w, r, redir.String(), 302)
	return nil, nil
}
開發者ID:shazow,項目名稱:mog,代碼行數:31,代碼來源:main.go

示例2: SetSource

func SetSource(c context.Context, w http.ResponseWriter, r *http.Request, u *User, g *goon.Goon) (interface{}, error) {
	var ss []*models.Source
	if err := json.NewDecoder(r.Body).Decode(&ss); err != nil {
		return nil, err
	}
	for _, s := range ss {
		p := &Protocol{
			ID:   s.Protocol,
			User: g.Key(u),
		}
		src := Source{
			ID:       s.Name,
			Protocol: g.Key(p),
			Blob:     s.Blob,
		}
		log.Println(s.Name, s.Protocol, len(s.Blob))
		_, err := g.Put(&src)
		if err != nil {
			return nil, err
		}
	}
	return nil, nil
}
開發者ID:shazow,項目名稱:mog,代碼行數:23,代碼來源:main.go

示例3: updateVillage

func updateVillage(us UpdateSchedule, g *goon.Goon) error {
	village := Village{No: us.VillageNo}
	if err := g.Get(&village); err != nil || village.Day <= 0 {
		return nil
	}
	village.Day++
	err := g.RunInTransaction(func(g *goon.Goon) error {
		vKey := g.Key(village)
		q3 := datastore.NewQuery("Person").Ancestor(vKey).Order("CreatedTime")
		people := make([]Person, 0, 10)
		_, err := g.GetAll(q3, &people)
		if err != nil {
			return err
		}
		// 3日目以降のみ投票処理
		var posts []Post
		if village.Day >= 3 {
			posts = Execute(people)
		} else if village.Day == 2 {
			t := setting.NpcName + "は無殘な死體で見つかった。"
			p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage}
			posts = append(posts, p)
			p2 := Post{Author: "System", AuthorID: "0", Time: time.Now(), Type: SystemMessage}
			p2.Text = setting.SecondDaySystemPost
			posts = append(posts, p2)
		}
		before := make([]Person, len(people))
		copy(before, people)
		posts = append(posts, Fortune(people)...)
		Raid(people)
		// Check Dead Person
		peaceful := true
		for i := range people {
			if !before[i].Dead && people[i].Dead {
				peaceful = false
				t := people[i].Name + "は無殘な死體で見つかった。"
				p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage}
				posts = append(posts, p)
			}
			people[i].VoteTarget = ""
			people[i].AbilityTarget = ""
		}
		if peaceful && village.Day >= 3 {
			t := "今日は誰も犠牲者がいないようだ。"
			p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage}
			posts = append(posts, p)
		}
		j := Judge(people)
		if j > 0 {
			village.Day *= -1
			var t string
			switch j {
			case 1:
				t = setting.VillagerWin
			case 2:
				t = setting.WerewolfWin
			case 3:
				t = setting.FoxWin
			}
			p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage}
			posts = append(posts, p)
		}
		_, err = g.Put(&village)
		if err != nil {
			return err
		}
		for i := range posts {
			posts[i].Day = village.Day
			if posts[i].Day <= -1 {
				posts[i].Day = -1
			}
			posts[i].ParentKey = vKey
			_, err = g.Put(&posts[i])
			if err != nil {
				return err
			}
		}
		for i := 0; i < len(people); i++ {
			people[i].ParentKey = vKey
			_, err = g.Put(&people[i])
			if err != nil {
				return err
			}
		}

		us.SetNextUpdateTime(time.Now())
		us.ParentKey = vKey
		_, err = g.Put(&us)
		if err != nil {
			return err
		}
		return nil
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:Blurmint199,項目名稱:Lycos,代碼行數:98,代碼來源:update.go


注:本文中的github.com/mjibson/goon.Goon.Put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。