From 0e77d94c621ce4a9f1b93ca6547bae4119f9190e Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 6 Oct 2019 20:22:07 +0200 Subject: added some comments future me will probably thank me for this --- src/docker.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/docker.go b/src/docker.go index 9ff9209..e4e6a17 100644 --- a/src/docker.go +++ b/src/docker.go @@ -84,7 +84,13 @@ func listDockerContainers() { // print all ips found for _, rawip := range companionContainerIPs { + + // if the ip starts with 172, it's the right one! if strings.Compare(rawip[0:3], "172") == 0 { + + // strip the "/16" or so suffix (this might break, see the todo + // below...) + // TODO: strip everything after the slash ip := rawip[:len(rawip)-3] fmt.Printf("ip: %s\n\n", ip) @@ -98,17 +104,27 @@ func listDockerContainers() { } } +// getStats makes an http request to the container with the given ip and port +// returning the result of the request to the /api/getStats endpoint func getStats(containerName string, containerPort uint16) (string, error) { + + // define the url where the request should go url := fmt.Sprintf("http://%s:%d/api/getStats", containerName, containerPort) log.Printf("url: %s", url) + + // make the request resp, err := http.Get(url) if err != nil { return "", fmt.Errorf("could not make the http get request: %v", err) } defer resp.Body.Close() + + // read the response body body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("could not read the request body: %v", err) } + + // returns the stats return string(body), nil } -- cgit 1.4.1