本文整理汇总了Golang中github.com/containerops/dockyard/models.Repository.Has方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.Has方法的具体用法?Golang Repository.Has怎么用?Golang Repository.Has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/dockyard/models.Repository
的用法示例。
在下文中一共展示了Repository.Has方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTagsListV2Handler
func GetTagsListV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if has, _, err := r.Has(namespace, repository); err != nil || has == false {
log.Error("[REGISTRY API V2] Repository not found: %v", repository)
result, _ := json.Marshal(map[string]string{"message": "Repository not found"})
return http.StatusNotFound, result
}
data := map[string]interface{}{}
tags := []string{}
data["name"] = fmt.Sprintf("%s/%s", namespace, repository)
for _, value := range r.Tags {
t := new(models.Tag)
if err := t.GetByKey(value); err != nil {
log.Error("[REGISTRY API V2] Tag not found: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Tag not found"})
return http.StatusNotFound, result
}
tags = append(tags, t.Name)
}
data["tags"] = tags
result, _ := json.Marshal(data)
return http.StatusOK, result
}
示例2: GetTagV1Handler
func GetTagV1Handler(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 tag 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 tag failed,read repository no found"})
return http.StatusNotFound, result
}
tag := map[string]string{}
for _, value := range repo.Tags {
t := new(models.Tag)
if err := db.Get(t, value); err != nil {
log.Error(fmt.Sprintf("[REGISTRY API V1] %s/%s Tags is not exist", namespace, repository))
result, _ := json.Marshal(map[string]string{"message": fmt.Sprintf("%s/%s Tags is not exist", namespace, repository)})
return http.StatusNotFound, result
}
tag[t.Name] = t.ImageId
}
result, _ := json.Marshal(tag)
return http.StatusOK, result
}
示例3: 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)
}
示例4: Handler
func (n *notification) Handler(ctx *macaron.Context) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
//Notification function just supports DockerV2 now
r := new(models.Repository)
if has, _, err := r.Has(namespace, repository); err != nil || has == false {
return
}
if r.Version != setting.APIVERSION_V2 {
return
}
actor := ActorRecord{Name: namespace}
repo := fmt.Sprintf("%v/%v", namespace, repository)
switch ctx.Req.Method {
case "HEAD":
digest := ctx.Params(":digest")
tarsum := strings.Split(digest, ":")[1]
i := new(models.Image)
if has, _ := i.HasTarsum(tarsum); has == false {
return
}
desc := Descriptor{
MediaType: DefaultMedisType,
Size: i.Size,
Digest: digest,
}
req := newReqRecord(utils.EncodeBasicAuth(namespace, "headblobsv2"), ctx.Req.Request)
requrl, err := module.NewURLBuilderFromRequest(ctx.Req.Request).BuildBlobURL(repo, desc.Digest)
if err != nil {
fmt.Errorf("[REGISTRY API V2] Head blobs and get request URL failed, error:: %v", err.Error())
}
b := newBridge(requrl, actor, req, notice)
Err := b.createBlobEventAndWrite(EventActionPull, repo, desc)
if Err.Err != nil {
ctx.Resp.WriteHeader(http.StatusForbidden)
return
} else if Err.StatusCode >= 300 {
ctx.Resp.WriteHeader(Err.StatusCode)
return
}
case "GET":
if flag := utils.Compare(ctx.Req.RequestURI, "/v2/"); flag == 0 {
return
}
if flag := strings.Contains(ctx.Req.RequestURI, "/blobs/"); flag == true {
digest := ctx.Params(":digest")
tarsum := strings.Split(digest, ":")[1]
i := new(models.Image)
if has, _ := i.HasTarsum(tarsum); has == false {
return
}
desc := Descriptor{
MediaType: BlobMediaType,
Size: i.Size,
Digest: digest,
}
req := newReqRecord(utils.EncodeBasicAuth(namespace, "getblobsv2"), ctx.Req.Request)
requrl, err := module.NewURLBuilderFromRequest(ctx.Req.Request).BuildBlobURL(repo, desc.Digest)
if err != nil {
fmt.Errorf("[REGISTRY API V2] Get blobs and get request URL failed, error:: %v", err.Error())
}
b := newBridge(requrl, actor, req, notice)
Err := b.createBlobEventAndWrite(EventActionPull, repo, desc)
if Err.Err != nil {
ctx.Resp.WriteHeader(http.StatusForbidden)
return
} else if Err.StatusCode >= 300 {
ctx.Resp.WriteHeader(Err.StatusCode)
return
}
return
}
if flag := strings.Contains(ctx.Req.RequestURI, "/manifests/"); flag == true {
t := new(models.Tag)
if err := t.Get(namespace, repository, ctx.Params(":tag")); err != nil {
return
}
digest, err := utils.DigestManifest([]byte(t.Manifest))
if err != nil {
fmt.Errorf("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
return
}
var sm SignedManifest
if err := json.Unmarshal([]byte(t.Manifest), &sm); err != nil {
//.........这里部分代码省略.........