50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package containers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"floares/config"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type Inspect struct {
|
|
Id string `json:"Id"`
|
|
Image string `json:"Image"`
|
|
NetworkSettings struct {
|
|
Ports map[string][]struct {
|
|
HostIp string `json:"HostIp"`
|
|
HostPort string `json:"HostPort"`
|
|
} `json:"Ports"`
|
|
Networks map[string]struct {
|
|
EndpointID string `json:"EndpointID"`
|
|
Gateway string `json:"Gateway"`
|
|
IPAddress string `json:"IPAddress"`
|
|
IPPrefixLen int `json:"IPPrefixLen"`
|
|
MacAddress string `json:"MacAddress"`
|
|
DriverOpts interface{} `json:"DriverOpts"`
|
|
IPAMConfig interface{} `json:"IPAMConfig"`
|
|
Links interface{} `json:"Links"`
|
|
Aliases []string `json:"Aliases"`
|
|
} `json:"Networks"`
|
|
} `json:"NetworkSettings"`
|
|
}
|
|
|
|
func InspectContainer(id string) (res Inspect) {
|
|
req, err := http.NewRequest(http.MethodGet, config.Entrypoint+"/v2.2.2/libpod/containers/"+id+"/json", nil)
|
|
if err != nil {
|
|
log.Println("request for containers list error:", err)
|
|
return
|
|
}
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
log.Println("request for containers list error:", err)
|
|
return
|
|
}
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&res)
|
|
if err != nil {
|
|
log.Println("json decode container list error:", err)
|
|
}
|
|
return
|
|
}
|