1
0
mirror of https://github.com/regclient/regclient.git synced 2025-07-29 09:01:11 +03:00

Refactoring the blob package

The main goal was to remove unnecessary interfaces. To avoid breaking
users, type aliases were used on the old interface names.
Comments were updated to better align with the godoc style.

Signed-off-by: Brandon Mitchell <git@bmitch.net>
This commit is contained in:
Brandon Mitchell
2023-09-26 20:18:19 -04:00
parent 934e52602a
commit cf47d837b7
6 changed files with 273 additions and 223 deletions

View File

@ -12,21 +12,11 @@ import (
"github.com/regclient/regclient/types/ref"
)
// Common interface is provided by all Blob implementations
type Common interface {
GetDescriptor() types.Descriptor
Response() *http.Response
RawHeaders() http.Header
// Common was previously an interface. A type alias is provided for upgrades.
type Common = *BCommon
// Deprecated: Digest should be replaced by GetDescriptor().Digest
Digest() digest.Digest
// Deprecated: Length should be replaced by GetDescriptor().Size
Length() int64
// Deprecated: MediaType should be replaced by GetDescriptor().MediaType
MediaType() string
}
type common struct {
// BCommon is a common struct for all blobs which includes various shared methods.
type BCommon struct {
r ref.Ref
desc types.Descriptor
blobSet bool
@ -34,32 +24,38 @@ type common struct {
resp *http.Response
}
// GetDescriptor returns the descriptor associated with the blob
func (b *common) GetDescriptor() types.Descriptor {
return b.desc
// GetDescriptor returns the descriptor associated with the blob.
func (c *BCommon) GetDescriptor() types.Descriptor {
return c.desc
}
// Digest returns the provided or calculated digest of the blob
func (b *common) Digest() digest.Digest {
return b.desc.Digest
// Digest returns the provided or calculated digest of the blob.
//
// Deprecated: Digest should be replaced by GetDescriptor().Digest.
func (c *BCommon) Digest() digest.Digest {
return c.desc.Digest
}
// Length returns the provided or calculated length of the blob
func (b *common) Length() int64 {
return b.desc.Size
// Length returns the provided or calculated length of the blob.
//
// Deprecated: Length should be replaced by GetDescriptor().Size.
func (c *BCommon) Length() int64 {
return c.desc.Size
}
// MediaType returns the Content-Type header received from the registry
func (b *common) MediaType() string {
return b.desc.MediaType
// MediaType returns the Content-Type header received from the registry.
//
// Deprecated: MediaType should be replaced by GetDescriptor().MediaType.
func (c *BCommon) MediaType() string {
return c.desc.MediaType
}
// RawHeaders returns the headers received from the registry
func (b *common) RawHeaders() http.Header {
return b.rawHeader
// RawHeaders returns the headers received from the registry.
func (c *BCommon) RawHeaders() http.Header {
return c.rawHeader
}
// Response returns the response associated with the blob
func (b *common) Response() *http.Response {
return b.resp
// Response returns the response associated with the blob.
func (c *BCommon) Response() *http.Response {
return c.resp
}