Exemple #1
0
func (ctx *Context) ListImagesHandler(w http.ResponseWriter, r *http.Request) {
	namespace := mux.Vars(r)["namespace"]
	repository := mux.Vars(r)["repository"]

	data, err := ctx.storage.GetContent(storage.ImageListPath(namespace, repository))
	if err != nil {
		sendResponse(w, "Repository not found", 404, nil, false)
		return
	}

	sendResponse(w, data, 200, nil, true)
}
Exemple #2
0
func (ctx *Context) PutImageHandler(w http.ResponseWriter, r *http.Request) {
	namespace := mux.Vars(r)["namespace"]
	repository := mux.Vars(r)["repository"]

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

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

	ctx.storage.PutContent(storage.ImageListPath(namespace, repository), body)

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