From d71ad5b3a6be14e002d130db9b9703732eee42e8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 10 Nov 2022 17:23:11 +0100 Subject: [PATCH] transport.NewHTTPReadSeeker: return concrete type, deprecate ReadSeekCloser General convention is to define interfaces on the receiver side, and to return concrete types. Signed-off-by: Sebastiaan van Stijn --- registry/client/transport/http_reader.go | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/registry/client/transport/http_reader.go b/registry/client/transport/http_reader.go index a409e494..71671158 100644 --- a/registry/client/transport/http_reader.go +++ b/registry/client/transport/http_reader.go @@ -20,17 +20,17 @@ var ( ) // ReadSeekCloser combines io.ReadSeeker with io.Closer. -type ReadSeekCloser interface { - io.ReadSeeker - io.Closer -} +// +// Deprecated: use [io.ReadSeekCloser]. +type ReadSeekCloser = io.ReadSeekCloser // NewHTTPReadSeeker handles reading from an HTTP endpoint using a GET // request. When seeking and starting a read from a non-zero offset // the a "Range" header will be added which sets the offset. +// // TODO(dmcgowan): Move this into a separate utility package -func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, errorHandler func(*http.Response) error) ReadSeekCloser { - return &httpReadSeeker{ +func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, errorHandler func(*http.Response) error) *HTTPReadSeeker { + return &HTTPReadSeeker{ ctx: ctx, client: client, url: url, @@ -38,7 +38,8 @@ func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, err } } -type httpReadSeeker struct { +// HTTPReadSeeker implements an [io.ReadSeekCloser]. +type HTTPReadSeeker struct { ctx context.Context client *http.Client url string @@ -63,7 +64,7 @@ type httpReadSeeker struct { err error } -func (hrs *httpReadSeeker) Read(p []byte) (n int, err error) { +func (hrs *HTTPReadSeeker) Read(p []byte) (n int, err error) { if hrs.err != nil { return 0, hrs.err } @@ -92,7 +93,7 @@ func (hrs *httpReadSeeker) Read(p []byte) (n int, err error) { return n, err } -func (hrs *httpReadSeeker) Seek(offset int64, whence int) (int64, error) { +func (hrs *HTTPReadSeeker) Seek(offset int64, whence int) (int64, error) { if hrs.err != nil { return 0, hrs.err } @@ -135,7 +136,7 @@ func (hrs *httpReadSeeker) Seek(offset int64, whence int) (int64, error) { return hrs.seekOffset, err } -func (hrs *httpReadSeeker) Close() error { +func (hrs *HTTPReadSeeker) Close() error { if hrs.err != nil { return hrs.err } @@ -152,7 +153,7 @@ func (hrs *httpReadSeeker) Close() error { return nil } -func (hrs *httpReadSeeker) reset() { +func (hrs *HTTPReadSeeker) reset() { if hrs.err != nil { return } @@ -162,7 +163,7 @@ func (hrs *httpReadSeeker) reset() { } } -func (hrs *httpReadSeeker) reader() (io.Reader, error) { +func (hrs *HTTPReadSeeker) reader() (io.Reader, error) { if hrs.err != nil { return nil, hrs.err }