From 6cbd22c5f0844f8d35789f2d98b3815b0481081d Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Tue, 9 Dec 2014 13:38:07 -0800 Subject: [PATCH] Implement tags HTTP API handler --- tags.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tags.go b/tags.go index d8cea3d3e..4916c1513 100644 --- a/tags.go +++ b/tags.go @@ -1,8 +1,10 @@ package registry import ( + "encoding/json" "net/http" + "github.com/docker/docker-registry/storage" "github.com/gorilla/handlers" ) @@ -22,7 +24,34 @@ type tagsHandler struct { *Context } +type tagsAPIResponse struct { + Name string `json:"name"` + Tags []string `json:"tags"` +} + // GetTags returns a json list of tags for a specific image name. func (th *tagsHandler) GetTags(w http.ResponseWriter, r *http.Request) { - // TODO(stevvooe): Implement this method. + defer r.Body.Close() + manifests := th.services.Manifests() + + tags, err := manifests.Tags(th.Name) + if err != nil { + switch err := err.(type) { + case storage.ErrUnknownRepository: + w.WriteHeader(404) + th.Errors.Push(ErrorCodeUnknownRepository, map[string]string{"name": th.Name}) + default: + th.Errors.PushErr(err) + } + return + } + + enc := json.NewEncoder(w) + if err := enc.Encode(tagsAPIResponse{ + Name: th.Name, + Tags: tags, + }); err != nil { + th.Errors.PushErr(err) + return + } }