feat: add image_inspect function

v-0.3.3
Jef Roosens 2022-12-15 11:55:04 +01:00
parent 598597f726
commit 9aebb3bedc
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 21 additions and 10 deletions

View File

@ -115,14 +115,14 @@ fn (mut d DockerConn) read_response_body(length int) !string {
fn (mut d DockerConn) read_response() !(http.Response, string) { fn (mut d DockerConn) read_response() !(http.Response, string) {
head := d.read_response_head()! head := d.read_response_head()!
if head.status().is_error() { if head.status().is_error() {
content_length := head.header.get(.content_length)!.int() content_length := head.header.get(.content_length)!.int()
body := d.read_response_body(content_length)! body := d.read_response_body(content_length)!
mut err := json.decode(DockerError, body)! 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 // 204 means "No Content", so we can assume nothing follows after this
if head.status() == .no_content { if head.status() == .no_content {

View File

@ -1,11 +1,16 @@
module docker module docker
import net.http { Method } import net.http { Method }
import types { Image }
import json import json
struct Image { pub fn (mut d DockerConn) image_inspect(image string) !Image {
pub: d.send_request(.get, '/images/$image/json')!
id string [json: Id] _, body := d.read_response()!
data := json.decode(Image, body)!
return data
} }
// pull_image pulls the given image:tag. // 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() content_length := head.header.get(.content_length)!.int()
body := d.read_response_body(content_length)! body := d.read_response_body(content_length)!
mut err := json.decode(DockerError, body)! mut err := json.decode(DockerError, body)!
err.status = head.status_code err.status = head.status_code
return err return err
} }

6
types/image.v 100644
View File

@ -0,0 +1,6 @@
module types
pub struct Image {
pub:
id string [json: Id]
}