本文整理匯總了Golang中github.com/drborges/appx.Datastore.Load方法的典型用法代碼示例。如果您正苦於以下問題:Golang Datastore.Load方法的具體用法?Golang Datastore.Load怎麽用?Golang Datastore.Load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/drborges/appx.Datastore
的用法示例。
在下文中一共展示了Datastore.Load方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RegisterDropbox
func RegisterDropbox(req *http.Request, render render.Render, registerDropboxForm RegisterDropboxForm, account *models.Account, logger *middlewares.Logger, ds *appx.Datastore) {
logger.Infof("You are in register dropbox")
authorization := &models.ExternalServiceAuthorization{
AuthorizationType: models.DropBox,
AccessToken: registerDropboxForm.AccessToken,
UserId: models.DropBox.String() + "-" + registerDropboxForm.UserId,
}
authorization.SetParentKey(account.Key())
err := ds.Load(authorization)
if err != nil {
println("I failed you becasue: %v", err.Error())
}
exists := err == nil
if err := ds.Save(authorization); err != nil {
logger.Errorf("Unable to register for dropbox %v", err)
render.JSON(http.StatusInternalServerError, "Unable to register dropbox")
return
}
if exists {
DropboxDelta(req, ds, account, authorization)
} else {
DropboxInit(req, ds, account, authorization)
}
render.Status(http.StatusOK)
}
示例2: storeTags
func (trail *Trail) storeTags(context appengine.Context, db *appx.Datastore) {
extractTags := func(data stream.T) stream.T {
trail := data.(*Trail)
return trail.AllTags()
}
err := rivers.FromData(trail).FlatMap(extractTags).Each(func(data stream.T) {
tag := data.(*Tag)
tag.SetParentKey(trail.ParentKey())
tag.ImagePath = trail.Path
tag.ImageProvider = DropBox
datastore.RunInTransaction(context, func(c appengine.Context) error {
if err := db.Load(tag); err == nil {
tag.LikenessCount++
} else {
tag.LikenessCount = 1
}
return db.Save(tag)
}, nil)
}).Drain()
if err != nil {
println(">>>>Screwed", err.Error())
}
}
示例3: ExternalServiceAuthorizationProvider
func ExternalServiceAuthorizationProvider(ds *appx.Datastore, martiniContext martini.Context, account *models.Account) {
authorization := &models.ExternalServiceAuthorization{}
authorization.SetParentKey(account.Key())
if err := ds.Load(authorization); err != nil {
panic(err)
}
martiniContext.Map(authorization)
}
示例4: alreadyCategorized
func alreadyCategorized(ds *appx.Datastore) stream.PredicateFn {
return func(data stream.T) bool {
trail := data.(*models.Trail)
err := ds.Load(trail)
if err == datastore.ErrNoSuchEntity {
return false
}
return err == nil
}
}
示例5: Login
func Login(render render.Render, loginForm LoginForm, logger *middlewares.Logger, db *appx.Datastore, request *http.Request) {
existingAccount := &models.Account{Id: loginForm.Id}
if err := db.Load(existingAccount); err == nil {
render.JSON(http.StatusOK, existingAccount)
return
}
account := models.Accounts.New(loginForm.Id)
if err := db.Save(account); err != nil {
logger.Errorf("Error while trying to login for account by id: %v", err.Error())
render.JSON(http.StatusBadRequest, err.Error())
return
}
render.JSON(http.StatusCreated, account)
}
示例6: likeness
func likeness(trailId string, likeness LikenessType, db *appx.Datastore, context appengine.Context) error {
trail := Trail{}
trail.SetEncodedKey(trailId)
if err := db.Load(&trail); err != nil {
println("The error: ", err.Error())
return err
}
trail.Likeness = likeness
trail.EvaluatedOn = time.Now()
if trail.Likeness == LikedIt {
trail.Tags = fetchLatLngFromGoogle(trail, context)
trail.storeTags(context, db)
}
if err := db.Save(&trail); err != nil {
println("The error: ", err.Error())
return err
}
return nil
}
示例7: FlagPostHandler
func FlagPostHandler(r render.Render, params martini.Params, appx *appx.Datastore) {
postId := params["post_id"]
response := model.Response{
ErrorCode: http.StatusOK,
Message: []string{},
Data: nil,
}
post := model.Post{}
post.SetEncodedKey(postId)
err := appx.Load(&post)
fmt.Print("aqui")
if err != nil {
fmt.Print("not found")
fmt.Print(err)
response.Message = []string{err.Error()}
response.ErrorCode = http.StatusBadRequest
} else {
fmt.Print("found")
fmt.Print(err)
post.Flagged = true
err = appx.Save(&post)
if err != nil {
fmt.Print("save problem")
fmt.Print(err)
response.Message = []string{err.Error()}
response.ErrorCode = http.StatusInternalServerError
} else {
postResource := &resources.PostResource{}
postResource.From(post)
response.Data = postResource
}
}
r.JSON(200, response)
}