feat: add image_inspect function
parent
598597f726
commit
9aebb3bedc
12
docker.v
12
docker.v
|
@ -115,14 +115,14 @@ fn (mut d DockerConn) read_response_body(length int) !string {
|
|||
fn (mut d DockerConn) read_response() !(http.Response, string) {
|
||||
head := d.read_response_head()!
|
||||
|
||||
if head.status().is_error() {
|
||||
content_length := head.header.get(.content_length)!.int()
|
||||
body := d.read_response_body(content_length)!
|
||||
if head.status().is_error() {
|
||||
content_length := head.header.get(.content_length)!.int()
|
||||
body := d.read_response_body(content_length)!
|
||||
mut err := json.decode(DockerError, body)!
|
||||
err.status = head.status_code
|
||||
err.status = head.status_code
|
||||
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 204 means "No Content", so we can assume nothing follows after this
|
||||
if head.status() == .no_content {
|
||||
|
|
13
images.v
13
images.v
|
@ -1,11 +1,16 @@
|
|||
module docker
|
||||
|
||||
import net.http { Method }
|
||||
import types { Image }
|
||||
import json
|
||||
|
||||
struct Image {
|
||||
pub:
|
||||
id string [json: Id]
|
||||
pub fn (mut d DockerConn) image_inspect(image string) !Image {
|
||||
d.send_request(.get, '/images/$image/json')!
|
||||
_, body := d.read_response()!
|
||||
|
||||
data := json.decode(Image, body)!
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// pull_image pulls the given image:tag.
|
||||
|
@ -17,7 +22,7 @@ pub fn (mut d DockerConn) pull_image(image string, tag string) ! {
|
|||
content_length := head.header.get(.content_length)!.int()
|
||||
body := d.read_response_body(content_length)!
|
||||
mut err := json.decode(DockerError, body)!
|
||||
err.status = head.status_code
|
||||
err.status = head.status_code
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
module types
|
||||
|
||||
pub struct Image {
|
||||
pub:
|
||||
id string [json: Id]
|
||||
}
|
Loading…
Reference in New Issue