mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client/inspect: Better Raw handling
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
@@ -65,3 +69,18 @@ func encodePlatform(platform *ocispec.Platform) (string, error) {
|
||||
}
|
||||
return string(p), nil
|
||||
}
|
||||
|
||||
func decodeWithRaw[T any](resp *http.Response, out *T) (raw []byte, _ error) {
|
||||
if resp == nil || resp.Body == nil {
|
||||
return nil, errors.New("empty response")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
tr := io.TeeReader(resp.Body, &buf)
|
||||
err := json.NewDecoder(tr).Decode(out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user