internal

package
v0.0.0-...-062ba55 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB
)
View Source
const (
	ParamOperations     = "op"
	ParamWidth          = "w"
	ParamHeight         = "h"
	ParamQuality        = "q"
	ParamStripMetadata  = "strip"
	ParamFormat         = "format"
	ParamPixelateFactor = "pixelatefactor"
)

Allowed URL parameters

View Source
const SignatureParam = "s"
View Source
const UserAgent = "mediator"

Variables

View Source
var ImageOperationsMap = map[string]ImageOperation{
	"fit":       FitImage,
	"smartcrop": SmartCropImage,
	"pixelate":  PixelateImage,
}

Functions

func ExportGIF

func ExportGIF(image *vips.ImageRef, imageOptions *ImageOptions) ([]byte, error)

func ExportJPEG

func ExportJPEG(image *vips.ImageRef, imageOptions *ImageOptions) ([]byte, error)

func ExportPNG

func ExportPNG(image *vips.ImageRef, imageOptions *ImageOptions) ([]byte, error)

func ExportWEBP

func ExportWEBP(image *vips.ImageRef, imageOptions *ImageOptions) ([]byte, error)

func FitImage

func FitImage(image *vips.ImageRef, imageOptions *ImageOptions) error

func ImageType

func ImageType(name string) vips.ImageType

func ImageTypeFromAccept

func ImageTypeFromAccept(accept string) vips.ImageType

func ImageTypeFromMimeType

func ImageTypeFromMimeType(mimeType string) vips.ImageType

func MimeTypeFromImageType

func MimeTypeFromImageType(code vips.ImageType) string

func NewHandler

func NewHandler(config *Config) *http.ServeMux

func NewImageHandler

func NewImageHandler(config *Config, handler http.Handler) http.Handler

func PixelateImage

func PixelateImage(image *vips.ImageRef, imageOptions *ImageOptions) error

func SmartCropImage

func SmartCropImage(image *vips.ImageRef, imageOptions *ImageOptions) error

Types

type AuthMiddleware

type AuthMiddleware struct {
	// contains filtered or unexported fields
}

func NewAuthMiddleware

func NewAuthMiddleware(config *Config, next http.Handler) *AuthMiddleware

func (*AuthMiddleware) ServeHTTP

func (h *AuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Config

type Config struct {
	DownloadMaxSize int
	DownloadTimeout time.Duration

	Sources      map[string]string
	SecretKey    string
	AuthToken    string
	CacheControl string
	PathPrefix   string

	HttpPort         int
	HttpIdleTimeout  time.Duration
	HttpReadTimeout  time.Duration
	HttpWriteTimeout time.Duration
}

func NewConfig

func NewConfig() (*Config, error)

type DefaultRouteHandler

type DefaultRouteHandler struct{}

func NewDefaultRouteHandler

func NewDefaultRouteHandler() *DefaultRouteHandler

func (*DefaultRouteHandler) ServeHTTP

func (h *DefaultRouteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DownloadedFile

type DownloadedFile struct {
	OriginalURL   string
	FinalURL      string
	ContentType   string
	ContentLength int
	StatusCode    int
	Buffer        bytes.Buffer
}

func DownloadFile

func DownloadFile(url string, maxSize int, requestTimeout time.Duration) (file *DownloadedFile, err error)

func ProxyFile

func ProxyFile(url string, maxSize int, requestTimeout time.Duration, r *http.Request, w http.ResponseWriter) (*DownloadedFile, error)

Download file and stream it back as response

func (*DownloadedFile) Size

func (f *DownloadedFile) Size() int

type HttpServer

type HttpServer struct {
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(config *Config, handler http.Handler) *HttpServer

func (*HttpServer) Start

func (s *HttpServer) Start()

func (*HttpServer) Stop

func (s *HttpServer) Stop()

type ImageExport

type ImageExport func(*vips.ImageRef, *ImageOptions) ([]byte, error)

type ImageOperation

type ImageOperation func(*vips.ImageRef, *ImageOptions) error

type ImageOptions

type ImageOptions struct {
	Operations      []string
	Width           int
	Height          int
	Quality         int
	StripMetadata   bool
	Format          vips.ImageType
	RequestedFormat string
	AutoRotate      bool
	PixelateFactor  int
	Page            int
}

func NewImageOptionsFromRequest

func NewImageOptionsFromRequest(r *http.Request) *ImageOptions

type ImageSource

type ImageSource struct {
	Source string
	Path   string
	URL    string
}

func NewImageSourceFromHttpRequest

func NewImageSourceFromHttpRequest(r *http.Request, config *Config) (*ImageSource, error)

func (*ImageSource) URLWithQueryString

func (imageSource *ImageSource) URLWithQueryString(r *http.Request) string

type ImageTransformHandler

type ImageTransformHandler struct {
	// contains filtered or unexported fields
}

func NewImageTransformHandler

func NewImageTransformHandler(config *Config) *ImageTransformHandler

func (*ImageTransformHandler) ServeHTTP

type LoggingMiddleware

type LoggingMiddleware struct {
	// contains filtered or unexported fields
}

func NewLoggingMiddleware

func NewLoggingMiddleware(next http.Handler) *LoggingMiddleware

func (*LoggingMiddleware) ServeHTTP

func (h *LoggingMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ProcessedImage

type ProcessedImage struct {
	Bytes []byte
	Mime  string
	Size  int
}

func ExportImage

func ExportImage(image *vips.ImageRef, imageOptions *ImageOptions) (*ProcessedImage, error)

func TransformImage

func TransformImage(imageBytes []byte, imageOptions *ImageOptions) (*ProcessedImage, error)

type ProxyHandler

type ProxyHandler struct {
	// contains filtered or unexported fields
}

func NewProxyHandler

func NewProxyHandler(config *Config) *ProxyHandler

func (*ProxyHandler) ServeHTTP

func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SignatureMiddleware

type SignatureMiddleware struct {
	// contains filtered or unexported fields
}

func NewSignatureMiddleware

func NewSignatureMiddleware(secret string, next http.Handler) *SignatureMiddleware

func (*SignatureMiddleware) ServeHTTP

func (h *SignatureMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SourceMiddleware

type SourceMiddleware struct {
	// contains filtered or unexported fields
}

func NewSourceMiddleware

func NewSourceMiddleware(config *Config, next http.Handler) *SourceMiddleware

func (*SourceMiddleware) ServeHTTP

func (h *SourceMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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