Exemplo n.º 1
0
func (ctx *Context) PutTagHandler(w http.ResponseWriter, r *http.Request) {
	namespace := mux.Vars(r)["namespace"]
	repository := mux.Vars(r)["repository"]
	tag := mux.Vars(r)["tag"]

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		sendResponse(w, "Couldn't read request body", 500, nil, false)
		return
	}

	var data string
	if err := json.Unmarshal(body, &data); err != nil {
		sendResponse(w, "Invalid data", 400, nil, false)
		return
	}

	exists, err := ctx.storage.Exists(storage.ImageJsonPath(data))
	if !exists || err != nil {
		sendResponse(w, "Image not found", 404, nil, false)
		return
	}

	ctx.storage.PutContent(storage.TagPathWithName(namespace, repository, tag), []byte(data))

	sendResponse(w, data, 200, nil, false)
}
Exemplo n.º 2
0
func (ctx *Context) DeleteTagHandler(w http.ResponseWriter, r *http.Request) {
	namespace := mux.Vars(r)["namespace"]
	repository := mux.Vars(r)["repository"]
	tag := mux.Vars(r)["tag"]

	err := ctx.storage.Remove(storage.TagPathWithName(namespace, repository, tag))
	if err != nil {
		sendResponse(w, "Tag not found", 404, nil, false)
		return
	}

	sendResponse(w, true, 200, nil, false)
}