refactor: remove all deprecation warnings
ci/woodpecker/push/lint Pipeline was successful Details

v-0.3.2
Jef Roosens 2022-11-01 19:19:52 +01:00
parent 80946dd295
commit b653f076d4
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 48 additions and 48 deletions

View File

@ -70,10 +70,10 @@ pub struct ContainerListItem {
mounts []MountPoint [json: Mounts] mounts []MountPoint [json: Mounts]
} }
pub fn (mut d DockerConn) container_list() ?[]ContainerListItem { pub fn (mut d DockerConn) container_list() ![]ContainerListItem {
d.send_request(Method.get, '/containers/json')? d.send_request(Method.get, '/containers/json')!
data := d.read_json_response<[]ContainerListItem>()? data := d.read_json_response<[]ContainerListItem>()!
return data return data
} }
@ -93,28 +93,28 @@ pub:
warnings []string [json: Warnings] warnings []string [json: Warnings]
} }
pub fn (mut d DockerConn) container_create(c NewContainer) ?CreatedContainer { pub fn (mut d DockerConn) container_create(c NewContainer) !CreatedContainer {
d.send_request_with_json(Method.post, '/containers/create', c)? d.send_request_with_json(Method.post, '/containers/create', c)!
head, res := d.read_response()? head, res := d.read_response()!
if head.status_code != 201 { if head.status_code != 201 {
data := json.decode(DockerError, res)? data := json.decode(DockerError, res)!
return error(data.message) return error(data.message)
} }
data := json.decode(CreatedContainer, res)? data := json.decode(CreatedContainer, res)!
return data return data
} }
// start_container starts the container with the given id. // start_container starts the container with the given id.
pub fn (mut d DockerConn) container_start(id string) ? { pub fn (mut d DockerConn) container_start(id string) ! {
d.send_request(Method.post, '/containers/$id/start')? d.send_request(Method.post, '/containers/$id/start')!
head, body := d.read_response()? head, body := d.read_response()!
if head.status_code != 204 { if head.status_code != 204 {
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }
@ -138,47 +138,47 @@ pub mut:
end_time time.Time [skip] end_time time.Time [skip]
} }
pub fn (mut d DockerConn) container_inspect(id string) ?ContainerInspect { pub fn (mut d DockerConn) container_inspect(id string) !ContainerInspect {
d.send_request(Method.get, '/containers/$id/json')? d.send_request(Method.get, '/containers/$id/json')!
head, body := d.read_response()? head, body := d.read_response()!
if head.status_code != 200 { if head.status_code != 200 {
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }
mut data := json.decode(ContainerInspect, body)? mut data := json.decode(ContainerInspect, body)!
// The Docker engine API *should* always return UTC time. // The Docker engine API *should* always return UTC time.
data.state.start_time = time.parse_rfc3339(data.state.start_time_str)? data.state.start_time = time.parse_rfc3339(data.state.start_time_str)!
if data.state.status == 'exited' { if data.state.status == 'exited' {
data.state.end_time = time.parse_rfc3339(data.state.end_time_str)? data.state.end_time = time.parse_rfc3339(data.state.end_time_str)!
} }
return data return data
} }
pub fn (mut d DockerConn) container_remove(id string) ? { pub fn (mut d DockerConn) container_remove(id string) ! {
d.send_request(Method.delete, '/containers/$id')? d.send_request(Method.delete, '/containers/$id')!
head, body := d.read_response()? head, body := d.read_response()!
if head.status_code != 204 { if head.status_code != 204 {
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }
} }
pub fn (mut d DockerConn) container_get_logs(id string) ?&StreamFormatReader { pub fn (mut d DockerConn) container_get_logs(id string) !&StreamFormatReader {
d.send_request(Method.get, '/containers/$id/logs?stdout=true&stderr=true')? d.send_request(Method.get, '/containers/$id/logs?stdout=true&stderr=true')!
head := d.read_response_head()? head := d.read_response_head()!
if head.status_code != 200 { if head.status_code != 200 {
content_length := head.header.get(http.CommonHeader.content_length)?.int() content_length := head.header.get(http.CommonHeader.content_length)!.int()
body := d.read_response_body(content_length)? body := d.read_response_body(content_length)!
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }

View File

@ -9,14 +9,14 @@ pub:
} }
// pull_image pulls the given image:tag. // pull_image pulls the given image:tag.
pub fn (mut d DockerConn) pull_image(image string, tag string) ? { pub fn (mut d DockerConn) pull_image(image string, tag string) ! {
d.send_request(Method.post, '/images/create?fromImage=$image&tag=$tag')? d.send_request(Method.post, '/images/create?fromImage=$image&tag=$tag')!
head := d.read_response_head()? head := d.read_response_head()!
if head.status_code != 200 { if head.status_code != 200 {
content_length := head.header.get(http.CommonHeader.content_length)?.int() content_length := head.header.get(http.CommonHeader.content_length)!.int()
body := d.read_response_body(content_length)? body := d.read_response_body(content_length)!
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }
@ -32,28 +32,28 @@ pub fn (mut d DockerConn) pull_image(image string, tag string) ? {
} }
// create_image_from_container creates a new image from a container. // create_image_from_container creates a new image from a container.
pub fn (mut d DockerConn) create_image_from_container(id string, repo string, tag string) ?Image { pub fn (mut d DockerConn) create_image_from_container(id string, repo string, tag string) !Image {
d.send_request(Method.post, '/commit?container=$id&repo=$repo&tag=$tag')? d.send_request(Method.post, '/commit?container=$id&repo=$repo&tag=$tag')!
head, body := d.read_response()? head, body := d.read_response()!
if head.status_code != 201 { if head.status_code != 201 {
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }
data := json.decode(Image, body)? data := json.decode(Image, body)!
return data return data
} }
// remove_image removes the image with the given id. // remove_image removes the image with the given id.
pub fn (mut d DockerConn) remove_image(id string) ? { pub fn (mut d DockerConn) remove_image(id string) ! {
d.send_request(Method.delete, '/images/$id')? d.send_request(Method.delete, '/images/$id')!
head, body := d.read_response()? head, body := d.read_response()!
if head.status_code != 200 { if head.status_code != 200 {
data := json.decode(DockerError, body)? data := json.decode(DockerError, body)!
return error(data.message) return error(data.message)
} }

View File

@ -35,13 +35,13 @@ struct VolumeListResponse {
warnings []string [json: Warnings] warnings []string [json: Warnings]
} }
pub fn (mut d DockerConn) volume_list() ?VolumeListResponse { pub fn (mut d DockerConn) volume_list() !VolumeListResponse {
d.send_request(Method.get, '/volumes')? d.send_request(Method.get, '/volumes')!
mut data := d.read_json_response<VolumeListResponse>()? mut data := d.read_json_response<VolumeListResponse>()!
for mut vol in data.volumes { for mut vol in data.volumes {
vol.created_at = time.parse_rfc3339(vol.created_at_str)? vol.created_at = time.parse_rfc3339(vol.created_at_str)!
} }
return data return data