images

package
v0.0.0-...-9518a5e Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 22 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 (
	// ErrInvalidContentType is what we return to indicate the provided data was of the wrong type.
	ErrInvalidContentType = errors.New("invalid content type")

	// 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 (
	// Providers represents what this library offers to external users in the form of dependencies.
	Providers = 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 Process.

Types

type Image

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

Image is a helper struct for handling images.

func (*Image) DataURI

func (i *Image) DataURI() string

DataURI converts image to base64 data URI.

func (*Image) Thumbnail

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

Thumbnail creates a thumbnail from an image.

func (*Image) Write

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

Write image to HTTP response.

type ImageUploadProcessor

type ImageUploadProcessor interface {
	Process(ctx context.Context, req *http.Request, filename string) (*Image, error)
}

ImageUploadProcessor process image uploads.

func NewImageUploadProcessor

func NewImageUploadProcessor(logger logging.Logger) ImageUploadProcessor

NewImageUploadProcessor provides a new ImageUploadProcessor.

type MockImageUploadProcessor

type MockImageUploadProcessor struct {
	mock.Mock
}

MockImageUploadProcessor is a mock ImageUploadProcessor.

func (*MockImageUploadProcessor) BuildAvatarUploadMiddleware

func (m *MockImageUploadProcessor) BuildAvatarUploadMiddleware(next http.Handler, encoderDecoder encoding.ServerEncoderDecoder, filename string) http.Handler

BuildAvatarUploadMiddleware satisfies the ImageUploadProcessor interface.

func (*MockImageUploadProcessor) Process

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

Process satisfies the ImageUploadProcessor interface.

Jump to

Keyboard shortcuts

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