-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
api_getcontainers.go
46 lines (38 loc) · 1.12 KB
/
api_getcontainers.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
42
43
44
45
46
package docker
import (
"context"
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/azukaar/cosmos-server/src/utils"
)
func GetContainerRoute(w http.ResponseWriter, req *http.Request) {
if utils.AdminOnly(w, req) != nil {
return
}
vars := mux.Vars(req)
containerId := vars["containerId"]
if req.Method == "GET" {
errD := Connect()
if errD != nil {
utils.Error("GetContainerRoute", errD)
utils.HTTPError(w, "Internal server error: "+errD.Error(), http.StatusInternalServerError, "LN001")
return
}
// get Docker container
container, err := DockerClient.ContainerInspect(context.Background(), containerId)
if err != nil {
utils.Error("GetContainerRoute: Error while getting container", err)
utils.HTTPError(w, "Container Get Error: " + err.Error(), http.StatusInternalServerError, "LN002")
return
}
json.NewEncoder(w).Encode(map[string]interface{}{
"status": "OK",
"data": container,
})
} else {
utils.Error("GetContainerRoute: Method not allowed " + req.Method, nil)
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
return
}
}