本文整理汇总了Golang中github.com/containerops/dockyard/models.Repository.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.Put方法的具体用法?Golang Repository.Put怎么用?Golang Repository.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/dockyard/models.Repository
的用法示例。
在下文中一共展示了Repository.Put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PutRepositoryV1Handler
func PutRepositoryV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
body, err := ctx.Req.Body().String()
if err != nil {
log.Error("[REGISTRY API V1] Get request body error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put V1 repository failed,request body is empty"})
return http.StatusBadRequest, result
}
r := new(models.Repository)
if err := r.Put(namespace, repository, body, ctx.Req.Header.Get("User-Agent"), setting.APIVERSION_V1); err != nil {
log.Error("[REGISTRY API V1] Put repository error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
if ctx.Req.Header.Get("X-Docker-Token") == "true" {
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"write")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例2: PutManifestsV2Handler
func PutManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
//TODO: to consider parallel situation
manifest := ManifestCtx
defer func() {
ManifestCtx = []byte{}
}()
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
agent := ctx.Req.Header.Get("User-Agent")
tag := ctx.Params(":tag")
if len(manifest) == 0 {
manifest, _ = ctx.Req.Body().Bytes()
}
digest, err := utils.DigestManifest(manifest)
if err != nil {
log.Error("[REGISTRY API V2] Failed to get manifest digest: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to get manifest digest"})
return http.StatusBadRequest, result
}
r := new(models.Repository)
if err := r.Put(namespace, repository, "", agent, setting.APIVERSION_V2); err != nil {
log.Error("[REGISTRY API V2] Failed to save repository %v/%v: %v", namespace, repository, err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to save repository"})
return http.StatusInternalServerError, result
}
err, schema := module.ParseManifest(manifest, namespace, repository, tag)
if err != nil {
log.Error("[REGISTRY API V2] Failed to decode manifest: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to decode manifest"})
return http.StatusBadRequest, result
}
random := fmt.Sprintf("%s://%s/v2/%s/%s/manifests/%s",
setting.ListenMode,
setting.Domains,
namespace,
repository,
digest)
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Location", random)
var status = []int{http.StatusBadRequest, http.StatusAccepted, http.StatusCreated}
result, _ := json.Marshal(map[string]string{})
return status[schema], result
}
示例3: PutManifestsV2Handler
func PutManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
//TODO: to consider parallel situation
manifest := ManifestCtx
defer func() {
ManifestCtx = []byte{}
}()
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
agent := ctx.Req.Header.Get("User-Agent")
repo := new(models.Repository)
if err := repo.Put(namespace, repository, "", agent, setting.APIVERSION_V2); err != nil {
log.Error("[REGISTRY API V2] Save repository failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
if len(manifest) == 0 {
manifest, _ = ctx.Req.Body().Bytes()
}
if err := module.ParseManifest(manifest); err != nil {
log.Error("[REGISTRY API V2] Decode Manifest Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Manifest converted failed"})
return http.StatusBadRequest, result
}
digest, err := utils.DigestManifest(manifest)
if err != nil {
log.Error("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get manifest digest failed"})
return http.StatusBadRequest, result
}
random := fmt.Sprintf("%s://%s/v2/%s/%s/manifests/%s",
setting.ListenMode,
setting.Domains,
namespace,
repository,
digest)
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Location", random)
result, _ := json.Marshal(map[string]string{})
return http.StatusAccepted, result
}
示例4: PutManifestsV2Handler
func PutManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
agent := ctx.Req.Header.Get("User-Agent")
repo := new(models.Repository)
if err := repo.Put(namespace, repository, "", agent, setting.APIVERSION_V2); err != nil {
log.Error("[REGISTRY API V2] Save repository failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
manifest, _ := ioutil.ReadAll(ctx.Req.Request.Body)
if err := modules.ParseManifest(manifest); err != nil {
log.Error("[REGISTRY API V2] Decode Manifest Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Manifest converted failed"})
return http.StatusBadRequest, result
}
digest, err := utils.DigestManifest(manifest)
if err != nil {
log.Error("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get manifest digest failed"})
return http.StatusBadRequest, result
}
random := fmt.Sprintf("https://%v/v2/%v/%v/manifests/%v",
setting.Domains,
namespace,
repository,
digest)
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Location", random)
result, _ := json.Marshal(map[string]string{})
return http.StatusAccepted, result
}