forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
38 lines (30 loc) · 921 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
package workerserver
import (
"encoding/json"
"net/http"
"github.com/concourse/atc"
"github.com/concourse/atc/api/accessor"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) ListWorkers(w http.ResponseWriter, r *http.Request) {
logger := s.logger.Session("list-workers")
var workers []db.Worker
acc := accessor.GetAccessor(r)
workers, err := s.dbWorkerFactory.VisibleWorkers(acc.TeamNames())
if err != nil {
logger.Error("failed-to-get-workers", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
atcWorkers := make([]atc.Worker, len(workers))
for i, savedWorker := range workers {
atcWorkers[i] = present.Worker(savedWorker)
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(atcWorkers)
if err != nil {
logger.Error("failed-to-encode-workers", err)
w.WriteHeader(http.StatusInternalServerError)
}
}