refactor: another change to internal api
ci/woodpecker/push/lint Pipeline was successful
Details
ci/woodpecker/push/lint Pipeline was successful
Details
parent
5bc54c37f3
commit
d31681843c
13
containers.v
13
containers.v
|
@ -12,7 +12,7 @@ pub struct ContainerListConfig {
|
|||
}
|
||||
|
||||
pub fn (mut d DockerConn) container_list(c ContainerListConfig) ![]ContainerListItem {
|
||||
d.request(.get, '/containers/json', {})
|
||||
d.request(.get, '/containers/json')
|
||||
d.params(c)
|
||||
d.send()!
|
||||
|
||||
|
@ -35,7 +35,7 @@ pub:
|
|||
}
|
||||
|
||||
pub fn (mut d DockerConn) container_create(c NewContainer) !CreatedContainer {
|
||||
d.request(.post, '/containers/create', {})
|
||||
d.request(.post, '/containers/create')
|
||||
d.body_json(c)
|
||||
d.send()!
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub fn (mut d DockerConn) container_create(c NewContainer) !CreatedContainer {
|
|||
|
||||
// start_container starts the container with the given id.
|
||||
pub fn (mut d DockerConn) container_start(id string) ! {
|
||||
d.request(.post, '/containers/$id/start', {})
|
||||
d.request(.post, '/containers/$id/start')
|
||||
d.send()!
|
||||
d.read_response()!
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ pub mut:
|
|||
}
|
||||
|
||||
pub fn (mut d DockerConn) container_inspect(id string) !ContainerInspect {
|
||||
d.request(.get, '/containers/$id/json', {})
|
||||
d.request(.get, '/containers/$id/json')
|
||||
d.send()!
|
||||
|
||||
mut data := d.read_json_response<ContainerInspect>()!
|
||||
|
@ -84,13 +84,14 @@ pub fn (mut d DockerConn) container_inspect(id string) !ContainerInspect {
|
|||
}
|
||||
|
||||
pub fn (mut d DockerConn) container_remove(id string) ! {
|
||||
d.request(.delete, '/containers/$id', {})
|
||||
d.request(.delete, '/containers/$id')
|
||||
d.send()!
|
||||
d.read_response()!
|
||||
}
|
||||
|
||||
pub fn (mut d DockerConn) container_get_logs(id string) !&StreamFormatReader {
|
||||
d.request(.get, '/containers/$id/logs', {
|
||||
d.request(.get, '/containers/$id/logs')
|
||||
d.params({
|
||||
'stdout': 'true'
|
||||
'stderr': 'true'
|
||||
})
|
||||
|
|
16
images.v
16
images.v
|
@ -3,7 +3,7 @@ module docker
|
|||
import types { Image }
|
||||
|
||||
pub fn (mut d DockerConn) image_inspect(image string) !Image {
|
||||
d.request(.get, '/images/$image/json', {})
|
||||
d.request(.get, '/images/$image/json')
|
||||
d.send()!
|
||||
|
||||
data := d.read_json_response<Image>()!
|
||||
|
@ -13,7 +13,8 @@ pub fn (mut d DockerConn) image_inspect(image string) !Image {
|
|||
|
||||
// image_pull pulls the given image:tag.
|
||||
pub fn (mut d DockerConn) image_pull(image string, tag string) ! {
|
||||
d.request(.post, '/images/create', {
|
||||
d.request(.post, '/images/create')
|
||||
d.params({
|
||||
'fromImage': image
|
||||
'tag': tag
|
||||
})
|
||||
|
@ -33,7 +34,8 @@ pub fn (mut d DockerConn) image_pull(image string, tag string) ! {
|
|||
|
||||
// create_image_from_container creates a new image from a container.
|
||||
pub fn (mut d DockerConn) image_from_container(id string, repo string, tag string) !Image {
|
||||
d.request(.post, '/commit', {
|
||||
d.request(.post, '/commit')
|
||||
d.params({
|
||||
'container': id
|
||||
'repo': repo
|
||||
'tag': tag
|
||||
|
@ -45,13 +47,17 @@ pub fn (mut d DockerConn) image_from_container(id string, repo string, tag strin
|
|||
|
||||
// remove_image removes the image with the given id.
|
||||
pub fn (mut d DockerConn) image_remove(id string) ! {
|
||||
d.request(.delete, '/images/$id', {})
|
||||
d.request(.delete, '/images/$id')
|
||||
d.send()!
|
||||
d.read_response()!
|
||||
}
|
||||
|
||||
pub fn (mut d DockerConn) image_tag(name string, repo string, tag string) ! {
|
||||
d.request(.post, '/images/$name/tag', {'repo': repo, 'tag': tag})
|
||||
d.request(.post, '/images/$name/tag')
|
||||
d.params({
|
||||
'repo': repo
|
||||
'tag': tag
|
||||
})
|
||||
d.send()!
|
||||
d.read_response()!
|
||||
}
|
||||
|
|
12
request.v
12
request.v
|
@ -5,17 +5,13 @@ import net.urllib
|
|||
import io
|
||||
import json
|
||||
|
||||
fn (mut d DockerConn) request(method http.Method, url string, params map[string]string) {
|
||||
fn (mut d DockerConn) request(method http.Method, url string) {
|
||||
d.method = method
|
||||
d.url = url
|
||||
d.content_type = ''
|
||||
d.body = ''
|
||||
|
||||
d.params.clear()
|
||||
|
||||
for key, value in params {
|
||||
d.params[key] = urllib.query_escape(value.replace("'", '"'))
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut d DockerConn) body(content_type string, body string) {
|
||||
|
@ -29,6 +25,11 @@ fn (mut d DockerConn) body_json<T>(data T) {
|
|||
}
|
||||
|
||||
fn (mut d DockerConn) params<T>(o T) {
|
||||
$if T is map[string]string {
|
||||
for key, value in o {
|
||||
d.params[key] = urllib.query_escape(value.replace("'", '"'))
|
||||
}
|
||||
} $else {
|
||||
$for field in T.fields {
|
||||
v := o.$(field.name)
|
||||
|
||||
|
@ -36,6 +37,7 @@ fn (mut d DockerConn) params<T>(o T) {
|
|||
d.params[field.name] = urllib.query_escape(v.str().replace("'", '"'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut d DockerConn) send() ! {
|
||||
|
|
Loading…
Reference in New Issue