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