本文整理汇总了Golang中github.com/containerops/dockyard/models.Image.Has方法的典型用法代码示例。如果您正苦于以下问题:Golang Image.Has方法的具体用法?Golang Image.Has怎么用?Golang Image.Has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/dockyard/models.Image
的用法示例。
在下文中一共展示了Image.Has方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetImageAncestryV1Handler
func GetImageAncestryV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
imageId := ctx.Params(":imageId")
i := new(models.Image)
if has, _, err := i.Has(imageId); err != nil {
log.Error("[REGISTRY API V1] Read Image Ancestry Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Read Image Ancestry Error"})
return http.StatusBadRequest, result
} else if has == false {
log.Error("[REGISTRY API V1] Read Image None: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Read Image None"})
return http.StatusNotFound, result
}
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(i.Ancestry)))
return http.StatusOK, []byte(i.Ancestry)
}
示例2: GetACIHandler
func GetACIHandler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
acifilename := ctx.Params(":acifilename")
acifile := strings.Trim(acifilename, ".asc")
tag := strings.Trim(acifile, ".aci")
t := new(models.Tag)
if err := t.Get(namespace, repository, tag); err != nil {
log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
return http.StatusNotFound, result
}
i := new(models.Image)
if has, _, err := i.Has(t.ImageId); err != nil || has != true {
log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
return http.StatusNotFound, result
}
var filepath string
if b := strings.Contains(acifilename, ".asc"); b == true {
filepath = i.SignPath
} else {
filepath = i.AciPath
}
content, err := ioutil.ReadFile(filepath)
if err != nil {
log.Error("[ACI API] Get ACI file failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get ACI file failed"})
return http.StatusInternalServerError, result
}
return http.StatusOK, content
}
示例3: GetImageLayerV1Handler
func GetImageLayerV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
imageId := ctx.Params(":imageId")
i := new(models.Image)
if has, _, err := i.Has(imageId); err != nil {
log.Error("[REGISTRY API V1] Read Image Layer File Status Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Read Image Layer file Error"})
return http.StatusBadRequest, result
} else if has == false {
log.Error("[REGISTRY API V1] Read Image None Error")
result, _ := json.Marshal(map[string]string{"message": "Read Image None"})
return http.StatusNotFound, result
}
layerfile := i.Path
if _, err := os.Stat(layerfile); err != nil {
log.Error("[REGISTRY API V1] Read Image file state error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Read Image file state error"})
return http.StatusBadRequest, result
}
file, err := ioutil.ReadFile(layerfile)
if err != nil {
log.Error("[REGISTRY API V1] Read Image file error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Read Image file error"})
return http.StatusBadRequest, result
}
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(file)))
return http.StatusOK, file
}