Exemplo n.º 1
0
Arquivo: list.go Projeto: ACPK/atc
func (s *Server) ListContainers(w http.ResponseWriter, r *http.Request) {
	params := r.URL.RawQuery

	hLog := s.logger.Session("list-containers", lager.Data{
		"params": params,
	})

	containerIdentifier, err := s.parseRequest(r)
	if err != nil {
		hLog.Error("failed-to-parse-request", err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	w.Header().Set("Content-Type", "application/json")

	hLog.Debug("listing-containers")

	containers, err := s.db.FindContainersByIdentifier(containerIdentifier)
	if err != nil {
		hLog.Error("failed-to-find-containers", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	hLog.Debug("listed", lager.Data{"container-count": len(containers)})

	presentedContainers := make([]atc.Container, len(containers))
	for i := 0; i < len(containers); i++ {
		container := containers[i]
		presentedContainers[i] = present.Container(container)
	}

	json.NewEncoder(w).Encode(presentedContainers)
}
Exemplo n.º 2
0
Arquivo: get.go Projeto: ACPK/atc
func (s *Server) GetContainer(w http.ResponseWriter, r *http.Request) {
	handle := r.FormValue(":id")

	hLog := s.logger.Session("container", lager.Data{
		"handle": handle,
	})

	container, found, err := s.db.GetContainer(handle)
	if err != nil {
		hLog.Error("failed-to-lookup-container", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	if !found {
		hLog.Debug("container-not-found")
		w.WriteHeader(http.StatusNotFound)
		return
	}

	hLog.Debug("found-container")

	presentedContainer := present.Container(container)

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(presentedContainer)
}