示例#1
0
func (this *ImageAPIV1Controller) GetImageLayer() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	if has, _, err := image.Has(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image Layer file Error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read Image None", nil)
		return
	}

	layerfile := image.Path

	if _, err := os.Stat(layerfile); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image file state error", nil)
		return
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image file error", nil)
		return
	}

	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Transfer-Encoding", "binary")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Length", string(int64(len(file))))
	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body(file)
	return
}
示例#2
0
func (this *ImageAPIV1Controller) GetImageAncestry() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	if has, _, err := image.Has(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image Ancestry Error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read Image None", nil)
		return
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(image.Ancestry))
	return
}