Exemple #1
0
func (ctx *Context) generateAncestry(imageId string, parentId string) error {
	if parentId == "" {
		selfAncestryJson, err := json.Marshal([]string{imageId})
		if err != nil {
			return err
		}
		if err := ctx.storage.PutContent(storage.ImageAncestryPath(imageId), selfAncestryJson); err != nil {
			return err
		}
		return nil
	}

	data, err := ctx.storage.GetContent(storage.ImageAncestryPath(parentId))
	if err != nil {
		return err
	}

	var ancestry []string
	if err := json.Unmarshal(data, &ancestry); err != nil {
		return err
	}

	newAncestry := []string{imageId}
	newAncestry = append(newAncestry, ancestry...)

	data, err = json.Marshal(newAncestry)
	if err != nil {
		return err
	}

	ctx.storage.PutContent(storage.ImageAncestryPath(imageId), data)

	return nil
}
Exemple #2
0
func (ctx *Context) GetImageAncestryHandler(w http.ResponseWriter, r *http.Request) {
	imageId := mux.Vars(r)["imageId"]

	data, err := ctx.storage.GetContent(storage.ImageAncestryPath(imageId))
	if err != nil {
		sendResponse(w, "Image not found", 404, nil, false)
		return
	}

	sendResponse(w, data, http.StatusOK, nil, true)
}