forked from vmware-archive/atc
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
41 lines (33 loc) · 999 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package volumeserver
import (
"encoding/json"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) ListVolumes(team db.Team) http.Handler {
hLog := s.logger.Session("list-volumes")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hLog.Debug("listing")
volumes, err := s.factory.GetTeamVolumes(team.ID())
if err != nil {
hLog.Error("failed-to-find-volumes", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
hLog.Debug("listed", lager.Data{"volume-count": len(volumes)})
presentedVolumes := make([]atc.Volume, len(volumes))
for i := 0; i < len(volumes); i++ {
volume := volumes[i]
presentedVolumes[i], err = present.Volume(volume)
if err != nil {
hLog.Error("failed-to-present-volume", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
json.NewEncoder(w).Encode(presentedVolumes)
})
}