From ec71ff464ff9d68e3f90e99529061c4183ad2885 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 29 May 2024 16:00:19 +0200 Subject: [PATCH] Step 4: Can create containers --- curl.go | 7 +++++-- index.html | 5 +++++ main.go | 11 ++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/curl.go b/curl.go index 1842483..24f362d 100644 --- a/curl.go +++ b/curl.go @@ -1,13 +1,14 @@ package main import ( + "bytes" "fmt" "io" "net" "net/http" ) -func curl(socket, method, path string) (io.ReadCloser, error) { +func curl(socket, method, path string, body []byte) (io.ReadCloser, error) { socketDial := func(proto, addr string) (conn net.Conn, err error) { return net.Dial("unix", socket) } @@ -19,11 +20,13 @@ func curl(socket, method, path string) (io.ReadCloser, error) { Transport: tr, } - req, err := http.NewRequest(method, path, nil) + req, err := http.NewRequest(method, path, bytes.NewReader(body)) if err != nil { return nil, fmt.Errorf("Error creating request: %w\n", err) } + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) if err != nil { return nil, fmt.Errorf("Error performing request: %w\n", err) diff --git a/index.html b/index.html index 2d6a9c5..b328440 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,12 @@ +
+ +