forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
40 lines (31 loc) · 902 Bytes
/
get.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
package containerserver
import (
"encoding/json"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) GetContainer(team db.Team) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handle := r.FormValue(":id")
hLog := s.logger.Session("container", lager.Data{
"handle": handle,
})
container, found, err := team.FindContainerByHandle(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)
})
}