forked from vieter-v/vieter
refactor: apply new vfmt defaults
This commit is contained in:
parent
53f5b68d08
commit
5f21e256ee
24 changed files with 138 additions and 138 deletions
|
|
@ -11,7 +11,7 @@ struct Container {
|
|||
|
||||
// containers returns a list of all currently running containers
|
||||
pub fn containers() ?[]Container {
|
||||
res := request('GET', urllib.parse('/v1.41/containers/json') ?) ?
|
||||
res := request('GET', urllib.parse('/v1.41/containers/json')?)?
|
||||
|
||||
return json.decode([]Container, res.text) or {}
|
||||
}
|
||||
|
|
@ -32,19 +32,19 @@ struct CreatedContainer {
|
|||
// create_container creates a container defined by the given configuration. If
|
||||
// successful, it returns the ID of the newly created container.
|
||||
pub fn create_container(c &NewContainer) ?string {
|
||||
res := request_with_json('POST', urllib.parse('/v1.41/containers/create') ?, c) ?
|
||||
res := request_with_json('POST', urllib.parse('/v1.41/containers/create')?, c)?
|
||||
|
||||
if res.status_code != 201 {
|
||||
return error('Failed to create container.')
|
||||
}
|
||||
|
||||
return json.decode(CreatedContainer, res.text) ?.id
|
||||
return json.decode(CreatedContainer, res.text)?.id
|
||||
}
|
||||
|
||||
// start_container starts a container with a given ID. It returns whether the
|
||||
// container was started or not.
|
||||
pub fn start_container(id string) ?bool {
|
||||
res := request('POST', urllib.parse('/v1.41/containers/$id/start') ?) ?
|
||||
res := request('POST', urllib.parse('/v1.41/containers/$id/start')?)?
|
||||
|
||||
return res.status_code == 204
|
||||
}
|
||||
|
|
@ -70,18 +70,18 @@ pub mut:
|
|||
// inspect_container returns the result of inspecting a container with a given
|
||||
// ID.
|
||||
pub fn inspect_container(id string) ?ContainerInspect {
|
||||
res := request('GET', urllib.parse('/v1.41/containers/$id/json') ?) ?
|
||||
res := request('GET', urllib.parse('/v1.41/containers/$id/json')?)?
|
||||
|
||||
if res.status_code != 200 {
|
||||
return error('Failed to inspect container.')
|
||||
}
|
||||
|
||||
mut data := json.decode(ContainerInspect, res.text) ?
|
||||
mut data := json.decode(ContainerInspect, res.text)?
|
||||
|
||||
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' {
|
||||
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
|
||||
|
|
@ -89,7 +89,7 @@ pub fn inspect_container(id string) ?ContainerInspect {
|
|||
|
||||
// remove_container removes a container with a given ID.
|
||||
pub fn remove_container(id string) ?bool {
|
||||
res := request('DELETE', urllib.parse('/v1.41/containers/$id') ?) ?
|
||||
res := request('DELETE', urllib.parse('/v1.41/containers/$id')?)?
|
||||
|
||||
return res.status_code == 204
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ pub fn remove_container(id string) ?bool {
|
|||
// get_container_logs retrieves the logs for a Docker container, both stdout &
|
||||
// stderr.
|
||||
pub fn get_container_logs(id string) ?string {
|
||||
res := request('GET', urllib.parse('/v1.41/containers/$id/logs?stdout=true&stderr=true') ?) ?
|
||||
res := request('GET', urllib.parse('/v1.41/containers/$id/logs?stdout=true&stderr=true')?)?
|
||||
mut res_bytes := res.text.bytes()
|
||||
|
||||
// Docker uses a special "stream" format for their logs, so we have to
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ fn send(req &string) ?http.Response {
|
|||
// Write the request to the socket
|
||||
s.write_string(req) or { return error('Failed to write request to socket ${docker.socket}.') }
|
||||
|
||||
s.wait_for_write() ?
|
||||
s.wait_for_write()?
|
||||
|
||||
mut c := 0
|
||||
mut buf := []u8{len: docker.buf_len}
|
||||
|
|
@ -56,7 +56,7 @@ fn send(req &string) ?http.Response {
|
|||
// A chunked HTTP response always ends with '0\r\n\r\n'.
|
||||
for res.len < 5 || res#[-5..] != [u8(`0`), `\r`, `\n`, `\r`, `\n`] {
|
||||
// Wait for the server to respond
|
||||
s.wait_for_write() ?
|
||||
s.wait_for_write()?
|
||||
|
||||
for {
|
||||
c = s.read(mut buf) or {
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ pub:
|
|||
|
||||
// pull_image pulls tries to pull the image for the given image & tag
|
||||
pub fn pull_image(image string, tag string) ?http.Response {
|
||||
return request('POST', urllib.parse('/v1.41/images/create?fromImage=$image&tag=$tag') ?)
|
||||
return request('POST', urllib.parse('/v1.41/images/create?fromImage=$image&tag=$tag')?)
|
||||
}
|
||||
|
||||
// create_image_from_container creates a new image from a container with the
|
||||
// given repo & tag, given the container's ID.
|
||||
pub fn create_image_from_container(id string, repo string, tag string) ?Image {
|
||||
res := request('POST', urllib.parse('/v1.41/commit?container=$id&repo=$repo&tag=$tag') ?) ?
|
||||
res := request('POST', urllib.parse('/v1.41/commit?container=$id&repo=$repo&tag=$tag')?)?
|
||||
|
||||
if res.status_code != 201 {
|
||||
return error('Failed to create image from container.')
|
||||
|
|
@ -28,7 +28,7 @@ pub fn create_image_from_container(id string, repo string, tag string) ?Image {
|
|||
|
||||
// remove_image removes the image with the given ID.
|
||||
pub fn remove_image(id string) ?bool {
|
||||
res := request('DELETE', urllib.parse('/v1.41/images/$id') ?) ?
|
||||
res := request('DELETE', urllib.parse('/v1.41/images/$id')?)?
|
||||
|
||||
return res.status_code == 200
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue