本文整理汇总了Golang中github.com/groob/ape/datastore.Datastore.SaveManifest方法的典型用法代码示例。如果您正苦于以下问题:Golang Datastore.SaveManifest方法的具体用法?Golang Datastore.SaveManifest怎么用?Golang Datastore.SaveManifest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/groob/ape/datastore.Datastore
的用法示例。
在下文中一共展示了Datastore.SaveManifest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleManifestsReplace
func handleManifestsReplace(db datastore.Datastore) httprouter.Handle {
return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
name := strings.TrimLeft(ps.ByName("name"), "/")
accept := acceptHeader(r)
manifest, err := db.Manifest(name)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to upddate manifest: %v", err))
return
}
payload := &models.Manifest{}
err = decodeRequest(r, payload)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to decode request payload: %v", err))
return
}
if err := db.SaveManifest(manifest); err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to save manifest: %v", err))
return
}
manifest = payload
manifest.Filename = name
// manifest updated ok, respond
respondOK(rw, manifest, accept)
}
}
示例2: handleManifestsUpdate
func handleManifestsUpdate(db datastore.Datastore) httprouter.Handle {
return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
name := strings.TrimLeft(ps.ByName("name"), "/")
accept := acceptHeader(r)
manifest, err := db.Manifest(name)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to delete manifest from the datastore: %v", err))
return
}
// decode payload from request body.
payload := &models.ManifestPayload{}
err = decodeRequest(r, payload)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to decode request payload: %v", err))
return
}
// update manifest from payload fields.
manifest.UpdateFromPayload(payload)
if err := db.SaveManifest(manifest); err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to save manifest: %v", err))
return
}
// manifest updated ok, respond
respondOK(rw, manifest, accept)
}
}
示例3: handleManifestsCreate
func handleManifestsCreate(db datastore.Datastore) httprouter.Handle {
return func(rw http.ResponseWriter, r *http.Request, _ httprouter.Params) {
accept := acceptHeader(r)
var manifest *models.Manifest
var payload struct {
Filename string `plist:"filename" json:"filename"`
*models.Manifest
}
err := decodeRequest(r, &payload)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to decode request payload: %v", err))
return
}
// filename is required in the payload
if payload.Filename == "" {
respondError(rw, http.StatusBadRequest, accept,
errors.New("the name field is required to create a manifest"))
return
}
// If the body contains a valid manifest, create it
manifest = payload.Manifest
manifest.Filename = payload.Filename
// create manifest in datastore
_, err = db.NewManifest(payload.Filename)
if err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to create new manifest: %v", err))
return
}
// save the manifest
if err := db.SaveManifest(manifest); err != nil {
respondError(rw, errStatus(err), accept,
fmt.Errorf("Failed to save manifest: %v", err))
return
}
respondCreated(rw, manifest, accept)
}
}