diff --git a/curl.go b/curl.go new file mode 100644 index 0000000..1842483 --- /dev/null +++ b/curl.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "io" + "net" + "net/http" +) + +func curl(socket, method, path string) (io.ReadCloser, error) { + socketDial := func(proto, addr string) (conn net.Conn, err error) { + return net.Dial("unix", socket) + } + + tr := &http.Transport{ + Dial: socketDial, + } + client := &http.Client{ + Transport: tr, + } + + req, err := http.NewRequest(method, path, nil) + if err != nil { + return nil, fmt.Errorf("Error creating request: %w\n", err) + } + + resp, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("Error performing request: %w\n", err) + } + return resp.Body, nil +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..2d6a9c5 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + Meetup Go + + + +

Meetup Go !

+ + + + + + + + + + + + + + +
CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
+ + + diff --git a/main.go b/main.go new file mode 100644 index 0000000..6143cfd --- /dev/null +++ b/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "io" + "log" + "net/http" +) + +func main() { + http.HandleFunc("GET /containers", func(w http.ResponseWriter, r *http.Request) { + rd, err := curl("/var/run/docker.sock", "GET", "http://d/v1.43/containers/json?all=true") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } else { + io.Copy(w, rd) + } + }) + + http.Handle("GET /", http.FileServer(http.Dir("."))) + + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..b247221 --- /dev/null +++ b/style.css @@ -0,0 +1,31 @@ +body { + display: flex; + flex-direction: column; + justify-content: center; + gap: .5rem; +} + +h1 { + border-bottom: 5px double forestgreen; + flex-grow: 1; + text-align: center; + padding-bottom: .66rem; +} + +table { + border-spacing:0; + border-collapse: collapse; +} +td, th { + padding: .5rem 0; + text-align: center; +} +tbody > tr { + border-top: 1px solid #222; +} +tbody > tr:nth-child(odd) { + background: #bbb; +} +tbody > tr:nth-child(even) { + background: #ddd; +}