imageproxy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCacheKey  = errors.New("invalid cache key; can't be decoded to URL")
	ErrCacheKeyNotFound = errors.New("cache key is not found")
)
View Source
var ErrRemoteResourceNotFound = errors.New("remote resource not found")

Functions

This section is empty.

Types

type CacheMetrics added in v0.2.1

type CacheMetrics struct {
	SourceFiles CacheSize `json:"sourceFiles"`
	Thumbnails  CacheSize `json:"thumbnails"`
	DeepZoom    struct {
		Descriptions CacheSize `json:"descriptions"`
		Tiles        CacheSize `json:"tiles"`
	} `json:"deepZoom"`
	Total CacheSize `json:"total,omitempty"`
}

func (CacheMetrics) TotalFiles added in v0.2.1

func (cm CacheMetrics) TotalFiles() uint64

func (CacheMetrics) TotalSizeInBytes added in v0.2.1

func (cm CacheMetrics) TotalSizeInBytes() uint64

type CacheSize added in v0.2.1

type CacheSize struct {
	Count       uint64
	SizeInBytes uint64
}

type CacheType added in v0.2.1

type CacheType string
const (
	Source             CacheType = "source"
	Cache              CacheType = "cache"
	Lru                CacheType = "lrucache"
	RejectDomain       CacheType = "domain_rejected"
	RejectReferrer     CacheType = "referrer_rejected"
	TargetRequestError CacheType = "remote_request_error"
)

type Option

type Option func(*Service) error

func SetAllowList added in v0.2.1

func SetAllowList(allowList []string) Option

func SetAllowPorts added in v0.3.0

func SetAllowPorts(ports []string) Option

func SetAllowedMimeTypes added in v0.2.1

func SetAllowedMimeTypes(allowedMimeTypes []string) Option

func SetCacheDir

func SetCacheDir(path string) Option

func SetDefaultImagePath added in v0.3.0

func SetDefaultImagePath(path string) Option

func SetEnableResize added in v0.2.1

func SetEnableResize(enabled bool) Option

func SetLogger added in v0.2.1

func SetLogger(logger *zerolog.Logger) Option

func SetLruCacheSize added in v0.2.1

func SetLruCacheSize(size int) Option

func SetMaxSizeCacheDir added in v0.2.1

func SetMaxSizeCacheDir(size int) Option

func SetProxyPrefix

func SetProxyPrefix(prefix string) Option

func SetProxyReferrer added in v0.2.0

func SetProxyReferrer(referrer []string) Option

func SetRefuseList added in v0.2.1

func SetRefuseList(refuseList []string) Option

func SetTimeout

func SetTimeout(duration int) Option

type ProxyOption added in v0.2.1

type ProxyOption string
const (
	Raw          ProxyOption = "raw"
	DeepZoom     ProxyOption = "deepzoom"
	Explain      ProxyOption = "explain"
	ProxyRequest ProxyOption = "request"
	Thumbnail    ProxyOption = "thumbnail"
)

type Request

type Request struct {
	SourceURL        string    // the request remote URL
	CacheKey         string    // the normalised cache key for both storage and retrieval
	TransformOptions string    // options to transform images or trigger actions
	RawQueryString   string    // not sure why this is needed
	CacheType        CacheType // CacheType is how the data is returned
	SubPath          string    // subPath is appended to raw cacheKey to get derivatives

	EnableTransform bool
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(input string, options ...RequestOption) (*Request, error)

func (*Request) GET

func (req *Request) GET() (*http.Request, error)

GET returns a *http.Request for the sourceURL

func (*Request) Read

func (req *Request) Read(path string) (io.ReadCloser, error)

Read returns an io.ReadCloser found at path from the cache. ErrCacheKeyNotFound is returned when nothing is found.

func (*Request) Remove added in v0.2.1

func (req *Request) Remove() error

func (*Request) Write

func (req *Request) Write(path string, r io.Reader) (int64, error)

Write writes all content of the reader to path in the cache

type RequestMetrics added in v0.2.1

type RequestMetrics struct {
	Source             uint64
	Cache              uint64
	LruCache           uint64
	RemoteRequestError uint64
	RejectDomain       uint64
	RejectReferrer     uint64
	RejectURI          uint64
	Resize             uint64
	DeepZoom           uint64
	Error              uint64
	Removed            uint64
	BytesServed        uint64
}

func (*RequestMetrics) IncBytesServed added in v0.2.1

func (m *RequestMetrics) IncBytesServed(size int64)

func (*RequestMetrics) IncCache added in v0.2.1

func (m *RequestMetrics) IncCache()

func (*RequestMetrics) IncDeepZoom added in v0.2.1

func (m *RequestMetrics) IncDeepZoom()

func (*RequestMetrics) IncError added in v0.2.1

func (m *RequestMetrics) IncError()

func (*RequestMetrics) IncLruCache added in v0.2.1

func (m *RequestMetrics) IncLruCache()

func (*RequestMetrics) IncRejectDomain added in v0.2.1

func (m *RequestMetrics) IncRejectDomain()

func (*RequestMetrics) IncRejectReferrer added in v0.2.1

func (m *RequestMetrics) IncRejectReferrer()

func (*RequestMetrics) IncRejectURI added in v0.2.1

func (m *RequestMetrics) IncRejectURI()

func (*RequestMetrics) IncRemoteRequestError added in v0.2.1

func (m *RequestMetrics) IncRemoteRequestError()

func (*RequestMetrics) IncRemoved added in v0.2.1

func (m *RequestMetrics) IncRemoved()

func (*RequestMetrics) IncResize added in v0.2.1

func (m *RequestMetrics) IncResize()

func (*RequestMetrics) IncSource added in v0.2.1

func (m *RequestMetrics) IncSource()

type RequestOption

type RequestOption func(req *Request) error

func SetEnableTransform added in v0.2.1

func SetEnableTransform(enabled bool) RequestOption

func SetRawQueryString

func SetRawQueryString(queryString string) RequestOption

func SetService

func SetService(s *Service) RequestOption

func SetTransform

func SetTransform(options string) RequestOption

type Service

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

func NewService

func NewService(options ...Option) (*Service, error)

func (*Service) CacheMetrics added in v0.2.1

func (s *Service) CacheMetrics() CacheMetrics

func (*Service) Do

func (s *Service) Do(ctx context.Context, req *Request, w io.Writer) error

func (*Service) RequestMetrics added in v0.2.1

func (s *Service) RequestMetrics() RequestMetrics

func (*Service) Routes

func (s *Service) Routes(pattern string, router chi.Router)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) SetServiceBuilder added in v0.3.0

func (s *Service) SetServiceBuilder(b *domain.ServiceBuilder)

func (*Service) Shutdown

func (s *Service) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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