server

package
v0.0.0-...-02bf5d9 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachingServer

type CachingServer struct {
	MediaServer
	// contains filtered or unexported fields
}

func NewCachingServer

func NewCachingServer(server MediaServer, storage MediaStorage, cacheSize int) (*CachingServer, error)

func (*CachingServer) GetImage

func (s *CachingServer) GetImage(ctx context.Context, fname string, class string) (io.Reader, string, error)

type ClassParams

type ClassParams struct {
	Width  int
	Height int
}

type ClassResolver

type ClassResolver func(context.Context, *http.Request) string

type MediaGetter

type MediaGetter interface {
	GetImage(ctx context.Context, fname string, class string) (io.Reader, string, error)
}

type MediaServer

type MediaServer interface {
	GetImage(ctx context.Context, fname string, class string) (io.Reader, string, error)
	ServeImage(ctx context.Context, getter MediaGetter, req *http.Request, w http.ResponseWriter, fname string) error
}

type MediaStorage

type MediaStorage interface {
	UploadFile(ctx context.Context, fname string, b []byte, contentType string) error
	DownloadFile(ctx context.Context, fname string) (io.ReadCloser, int64, string, error)
	ObjectExists(ctx context.Context, fname string) (bool, error)
}

type Option

type Option func(s *options)

func WithClass

func WithClass(name string, params ClassParams) Option

func WithClassResolver

func WithClassResolver(r ClassResolver) Option

func WithPermaCache

func WithPermaCache(enabled bool) Option

type Server

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

func New

func New(storage MediaStorage, o ...Option) (*Server, func())

func (Server) GetImage

func (s Server) GetImage(ctx context.Context, fname string, class string) (io.Reader, string, error)

get the reader with downloaded and transformed image after all transformations

func (Server) ServeImage

func (s Server) ServeImage(ctx context.Context, getter MediaGetter, req *http.Request, w http.ResponseWriter, fname string) error

type ServerWrapper

type ServerWrapper struct {
	MediaServer
	// contains filtered or unexported fields
}

ServerWrapper wraps the media Server to provide request deduplication and concurrency limiting

func NewWrapper

func NewWrapper(server MediaServer, maxConcurrent int64) *ServerWrapper

NewWrapper creates a new ServerWrapper with the given concurrency limit

func (*ServerWrapper) GetImage

func (w *ServerWrapper) GetImage(ctx context.Context, fname string, class string) (io.Reader, string, error)

GetImage implements the same interface as Server.GetImage but with deduplication and concurrency limiting

Directories

Path Synopsis
storage
s3

Jump to

Keyboard shortcuts

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