本文整理匯總了Golang中github.com/mjibson/goon.Goon類的典型用法代碼示例。如果您正苦於以下問題:Golang Goon類的具體用法?Golang Goon怎麽用?Golang Goon使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Goon類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例2: DeleteSource
func DeleteSource(c context.Context, w http.ResponseWriter, r *http.Request, u *User, g *goon.Goon) (interface{}, error) {
var d models.Delete
if err := json.NewDecoder(r.Body).Decode(&d); err != nil {
return nil, err
}
p := &Protocol{
ID: d.Protocol,
User: g.Key(u),
}
s := &Source{
ID: d.Name,
Protocol: g.Key(p),
}
err := g.Delete(g.Key(s))
return nil, err
}
示例3: GetSource
func GetSource(c context.Context, w http.ResponseWriter, r *http.Request, u *User, g *goon.Goon) (interface{}, error) {
var ss []*Source
k := g.Kind(&Source{})
q := datastore.NewQuery(k).Ancestor(g.Key(u))
if _, err := g.GetAll(q, &ss); err != nil {
return nil, err
}
ret := make([]*models.Source, len(ss))
for i, s := range ss {
ret[i] = &models.Source{
Protocol: s.Protocol.StringID(),
Name: s.ID,
Blob: s.Blob,
}
}
return ret, nil
}
示例4: 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
}
示例5: 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
}