本文整理匯總了Golang中github.com/drborges/appx.Datastore.Save方法的典型用法代碼示例。如果您正苦於以下問題:Golang Datastore.Save方法的具體用法?Golang Datastore.Save怎麽用?Golang Datastore.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/drborges/appx.Datastore
的用法示例。
在下文中一共展示了Datastore.Save方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: saveBatch
func saveBatch(ds *appx.Datastore) stream.EachFn {
return func(data stream.T) {
trails := data.(*appx.DatastoreBatch)
if err := ds.Save(trails.Items...); err != nil {
panic(err)
}
}
}
示例4: UpdateAccount
func UpdateAccount(render render.Render, accountUpdateForm AccountUpdateForm, account *models.Account, db *appx.Datastore) {
account.FirstName = accountUpdateForm.FirstName
account.LastName = accountUpdateForm.LastName
account.Email = accountUpdateForm.Email
if err := db.Save(account); err != nil {
render.JSON(http.StatusInternalServerError, "Unable to register dropbox")
}
render.Status(http.StatusOK)
}
示例5: LoginHandler
func LoginHandler(r render.Render, user model.User, appx *appx.Datastore) {
response := model.Response{
ErrorCode: http.StatusOK,
Message: []string{},
Data: nil,
}
isValid, validationErr := user.IsValid()
if !isValid {
response.ErrorCode = http.StatusBadRequest
response.Message = validationErr
} else {
err := appx.Save(&user)
if err != nil {
log.Printf("Error: %v", err)
response.ErrorCode = http.StatusInternalServerError
response.Message = append(response.Message, err.Error())
} else {
response.Data = user
}
}
r.JSON(200, response)
}
示例6: CreatePostHandler
func CreatePostHandler(r render.Render, post model.Post, appx *appx.Datastore, location middleware.RequestLocation) {
response := model.Response{
ErrorCode: http.StatusOK,
Message: []string{},
Data: nil,
}
post.CarPlate = strings.ToUpper(post.CarPlate)
post.Country = location.Country
post.CreatedAt = time.Now()
isValid, validationErr := post.IsValid(location.Country)
if !isValid {
response.ErrorCode = http.StatusBadRequest
response.Message = validationErr
} else {
err := appx.Save(&post)
if err != nil {
log.Printf("Error: %+v", err)
response.ErrorCode = http.StatusInternalServerError
response.Message = append(response.Message, err.Error())
} else {
postResource := &resources.PostResource{}
postResource.From(post)
response.Data = postResource
}
}
r.JSON(200, response)
}
示例7: 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)
}
示例8: DropboxDelta
func DropboxDelta(req *http.Request, ds *appx.Datastore, authorization *models.ExternalServiceAuthorization, existingItem stream.PredicateFn) {
dropboxClient := dropboxClient(newappengine.NewContext(req), authorization.AccessToken)
builder := DropboxDeltaProducerBuilder{Client: dropboxClient, CurrentCursor: authorization.LastCursor}
deltaStream, debugStream := rivers.
From(builder.Build()).
Drop(nonMediaFiles).
Map(toTrailForAuthorization(authorization)).
Drop(existingItem).
Split()
println("About to split data")
err := deltaStream.BatchBy(&appx.DatastoreBatch{Size: 500}).
Each(saveBatch(ds)).
Drain()
println(fmt.Sprintf("Error while batch saving the data: %v", err))
total, errTotal := debugStream.Reduce(0, func(sum, item stream.T) stream.T {
return sum.(int) + 1
}).CollectFirst()
if errTotal != nil {
println(fmt.Sprintf("########## Guaging error %v", err))
return
}
println(fmt.Sprintf("Total entries: %v", total.(int)))
authorization.LastCursor = builder.CurrentCursor
ds.Save(authorization)
if err != nil {
println(fmt.Sprintf("########## Delta error %v", err))
}
}
示例9: 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
}
示例10: 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)
}