@@ -10,41 +10,21 @@ import (
1010 "github.com/docker/docker/api/types/image"
1111)
1212
13- type imageInspectClientOpt struct {
14- raw * bytes.Buffer
15- apiOptions image.InspectOptions
16- }
17-
18- type ImageInspectOpt func (* imageInspectClientOpt )
19-
20- // ImageInspectWithRawResponse instructs the client to additionally store the
21- // raw inspect response in the provided buffer.
22- func ImageInspectWithRawResponse (raw * bytes.Buffer ) ImageInspectOpt {
23- return func (opts * imageInspectClientOpt ) {
24- opts .raw = raw
25- }
26- }
13+ type ImageInspectOpts struct {
14+ image.InspectOptions
2715
28- // ImageInspectWithOpts sets the API options for the image inspect operation.
29- func ImageInspectWithOpts (opts image.InspectOptions ) ImageInspectOpt {
30- return func (clientOpts * imageInspectClientOpt ) {
31- clientOpts .apiOptions = opts
32- }
16+ // Raw is an optional writer to write the raw inspect response to.
17+ Raw io.Writer
3318}
3419
3520// ImageInspect returns the image information.
36- func (cli * Client ) ImageInspect (ctx context.Context , imageID string , inspectOpts ... ImageInspectOpt ) (image.InspectResponse , error ) {
21+ func (cli * Client ) ImageInspect (ctx context.Context , imageID string , opts ImageInspectOpts ) (image.InspectResponse , error ) {
3722 if imageID == "" {
3823 return image.InspectResponse {}, objectNotFoundError {object : "image" , id : imageID }
3924 }
4025
41- var opts imageInspectClientOpt
42- for _ , opt := range inspectOpts {
43- opt (& opts )
44- }
45-
4626 query := url.Values {}
47- if opts .apiOptions . Manifests {
27+ if opts .Manifests {
4828 if err := cli .NewVersionError (ctx , "1.48" , "manifests" ); err != nil {
4929 return image.InspectResponse {}, err
5030 }
@@ -57,17 +37,13 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
5737 return image.InspectResponse {}, err
5838 }
5939
60- buf := opts .raw
61- if buf == nil {
62- buf = & bytes.Buffer {}
63- }
64-
65- if _ , err := io .Copy (buf , serverResp .body ); err != nil {
66- return image.InspectResponse {}, err
40+ var reader io.Reader = serverResp .body
41+ if opts .Raw != nil {
42+ reader = io .TeeReader (serverResp .body , opts .Raw )
6743 }
6844
6945 var response image.InspectResponse
70- err = json .Unmarshal ( buf . Bytes (), & response )
46+ err = json .NewDecoder ( reader ). Decode ( & response )
7147 return response , err
7248}
7349
@@ -76,7 +52,7 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
7652// TODeprecate: Use [ImageInspect] instead.
7753func (cli * Client ) ImageInspectWithRaw (ctx context.Context , imageID string ) (image.InspectResponse , []byte , error ) {
7854 var buf bytes.Buffer
79- resp , err := cli .ImageInspect (ctx , imageID , ImageInspectWithRawResponse ( & buf ) )
55+ resp , err := cli .ImageInspect (ctx , imageID , ImageInspectOpts { Raw : & buf } )
8056 if err != nil {
8157 return image.InspectResponse {}, nil , err
8258 }
0 commit comments