img

package
v0.0.0-...-3dc0db1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(
	ctx context.Context,
	hc HTTPClient,
	imageURL string,
) ([]byte, error)

Download downloads the image located at the url provided. If it's a data url the image is extracted from it. Otherwise it's downloaded using the url.

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient defines the methods an HTTPClient implementation must provide.

type Store

type Store interface {
	// DownloadAndSaveImage downloads the image located at the url provided and
	// stores it returning the image ID.
	DownloadAndSaveImage(ctx context.Context, imageURL string) (imageID string, err error)

	// GetImage returns the image identified by the ID and version provided.
	GetImage(ctx context.Context, imageID, version string) (datd []byte, err error)

	// SaveImage stores an image returning the image ID.
	SaveImage(ctx context.Context, data []byte) (imageID string, err error)
}

Store describes the methods an image.Store implementation must provide.

type StoreMock

type StoreMock struct {
	mock.Mock
}

StoreMock is a mock implementation of the img.Store interface.

func (*StoreMock) DownloadAndSaveImage

func (m *StoreMock) DownloadAndSaveImage(ctx context.Context, imageURL string) (string, error)

DownloadAndSaveImage implements the img.Store interface.

func (*StoreMock) GetImage

func (m *StoreMock) GetImage(ctx context.Context, imageID, version string) ([]byte, error)

GetImage implements the img.Store interface.

func (*StoreMock) SaveImage

func (m *StoreMock) SaveImage(ctx context.Context, data []byte) (string, error)

SaveImage implements the img.Store interface.

type Version

type Version struct {
	Version string
	Data    []byte
}

Version represents a specific size version of an image.

func GenerateVersions

func GenerateVersions(data []byte) ([]*Version, error)

GenerateVersions generates multiple versions of different sizes for the image provided.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL