本文整理汇总了Golang中github.com/groob/ape/datastore.Datastore.NewManifest方法的典型用法代码示例。如果您正苦于以下问题:Golang Datastore.NewManifest方法的具体用法?Golang Datastore.NewManifest怎么用?Golang Datastore.NewManifest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/groob/ape/datastore.Datastore
的用法示例。
在下文中一共展示了Datastore.NewManifest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}