1
0
mirror of https://github.com/regclient/regclient.git synced 2025-04-18 22:44:00 +03:00
regclient/types/blob/blob.go
Brandon Mitchell 4b796535cb Adjusting types to use New/Opts initializers
Signed-off-by: Brandon Mitchell <git@bmitch.net>
2022-01-02 21:05:09 -05:00

62 lines
1.0 KiB
Go

package blob
import (
"io"
"net/http"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/regclient/regclient/types/ref"
)
// Blob interface is used for returning blobs
type Blob interface {
Common
RawBody() ([]byte, error)
}
type BlobConfig struct {
desc ociv1.Descriptor
header http.Header
image ociv1.Image
r ref.Ref
rc io.ReadCloser
resp *http.Response
}
type Opts func(*BlobConfig)
func WithDesc(d ociv1.Descriptor) Opts {
return func(bc *BlobConfig) {
bc.desc = d
}
}
func WithHeader(header http.Header) Opts {
return func(bc *BlobConfig) {
bc.header = header
}
}
func WithImage(image ociv1.Image) Opts {
return func(bc *BlobConfig) {
bc.image = image
}
}
func WithReadCloser(rc io.ReadCloser) Opts {
return func(bc *BlobConfig) {
bc.rc = rc
}
}
func WithRef(r ref.Ref) Opts {
return func(bc *BlobConfig) {
bc.r = r
}
}
func WithResp(resp *http.Response) Opts {
return func(bc *BlobConfig) {
bc.resp = resp
if bc.header == nil {
bc.header = resp.Header
}
}
}