images

package
v0.0.0-...-98cd694 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Unlicense Imports: 23 Imported by: 0

Documentation

Overview

Package images is largely (and respectfully) inspired by/copied from this repo: github.com/olahol/go-imageupload

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidImageContentType is what we return to indicate the provided image was of the wrong type.
	ErrInvalidImageContentType = errors.New("invalid image content type")
)
View Source
var (
	// ProvidersImages represents what this library offers to external users in the form of dependencies.
	ProvidersImages = wire.NewSet(
		NewImageUploadProcessor,
	)
)

Functions

func LimitFileSize

func LimitFileSize(maxSize uint16, res http.ResponseWriter, req *http.Request)

LimitFileSize limits the size of uploaded files, for use before ProcessFile.

Types

type MediaUploadProcessor

type MediaUploadProcessor interface {
	ProcessFile(ctx context.Context, req *http.Request, filename string) (*Upload, error)
	ProcessFiles(ctx context.Context, req *http.Request, filenamePrefix string) ([]*Upload, error)
}

MediaUploadProcessor processes media uploads.

func NewImageUploadProcessor

func NewImageUploadProcessor(logger logging.Logger, tracerProvider tracing.TracerProvider) MediaUploadProcessor

NewImageUploadProcessor provides a new MediaUploadProcessor.

type MockImageUploadProcessor

type MockImageUploadProcessor struct {
	mock.Mock
}

MockImageUploadProcessor is a mock MediaUploadProcessor.

func (*MockImageUploadProcessor) ProcessFile

func (m *MockImageUploadProcessor) ProcessFile(ctx context.Context, req *http.Request, filename string) (*Upload, error)

ProcessFile satisfies the MediaUploadProcessor interface.

func (*MockImageUploadProcessor) ProcessFiles

func (m *MockImageUploadProcessor) ProcessFiles(ctx context.Context, req *http.Request, filenamePrefix string) ([]*Upload, error)

type Upload

type Upload struct {
	Filename    string
	ContentType string
	Data        []byte
	Size        int
}

Upload is a helper struct for handling images.

func (*Upload) DataURI

func (i *Upload) DataURI() string

DataURI converts image to base64 data URI.

func (*Upload) Thumbnail

func (i *Upload) Thumbnail(width, height uint, filename string) (*Upload, error)

Thumbnail creates a thumbnail from an image.

func (*Upload) Write

func (i *Upload) Write(w http.ResponseWriter) error

Write image to HTTP response.

Jump to

Keyboard shortcuts

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