golang - working with readCloser



In so many occasion, in this case, i worked with docker ContainerStats which return a "readCloser" type. To convert this into string, you need the code below :-

Sometimes can be tricky trying to figure which object and method to use.


    containerStats, err := dc.targetClient.ContainerStats(context.Background(), dc.containerId, false)

    buf := new(bytes.Buffer)
    buf.ReadFrom(containerStats.Body)
    fmt.Println(buf.String())


Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type