diff --git a/docker.v b/docker.v index 701ea1f..7eb5ea2 100644 --- a/docker.v +++ b/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 { diff --git a/images.v b/images.v index 00316d7..a6f2a23 100644 --- a/images.v +++ b/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 } diff --git a/types/image.v b/types/image.v new file mode 100644 index 0000000..9665cde --- /dev/null +++ b/types/image.v @@ -0,0 +1,6 @@ +module types + +pub struct Image { +pub: + id string [json: Id] +}