本文整理汇总了Golang中github.com/containerops/dockyard/models.Repository.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.Save方法的具体用法?Golang Repository.Save怎么用?Golang Repository.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/dockyard/models.Repository
的用法示例。
在下文中一共展示了Repository.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetRepositoryImagesV1Handler
func GetRepositoryImagesV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
repo := new(models.Repository)
if has, _, err := repo.Has(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Read repository json error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get V1 repository images failed,wrong name or repository"})
return http.StatusBadRequest, result
} else if has == false {
log.Error("[REGISTRY API V1] Read repository no found, %v/%v", namespace, repository)
result, _ := json.Marshal(map[string]string{"message": "Get V1 repository images failed,repository no found"})
return http.StatusNotFound, result
}
repo.Download += 1
if err := repo.Save(); err != nil {
log.Error("[REGISTRY API V1] Update download count error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Save V1 repository failed"})
return http.StatusBadRequest, result
}
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"read")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(repo.JSON)))
return http.StatusOK, []byte(repo.JSON)
}
示例2: GetRepositoryImagesV1Handler
func GetRepositoryImagesV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if exists, err := r.Get(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Failed to get repository %v/%v context: %v", namespace, repository, err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to get repository context"})
return http.StatusBadRequest, result
} else if exists == false {
log.Error("[REGISTRY API V1] Not found repository %v/%v", namespace, repository)
result, _ := json.Marshal(map[string]string{"message": "Not found repository"})
return http.StatusNotFound, result
}
r.Download += 1
if err := r.Save(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Failed to save repository %v/%v context: %v", namespace, repository, err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to save repository context"})
return http.StatusBadRequest, result
}
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"read")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(r.JSON)))
return http.StatusOK, []byte(r.JSON)
}