当前位置: 首页>>代码示例>>Golang>>正文


Golang Datastore.SaveManifest方法代码示例

本文整理汇总了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)
	}
}
开发者ID:groob,项目名称:ape,代码行数:32,代码来源:manifest.go

示例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)
	}
}
开发者ID:groob,项目名称:ape,代码行数:33,代码来源:manifest.go

示例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)
	}
}
开发者ID:groob,项目名称:ape,代码行数:45,代码来源:manifest.go


注:本文中的github.com/groob/ape/datastore.Datastore.SaveManifest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。