golazy.dev golazy.dev / lazyassets Index | Files

package lazyassets

import "golazy.dev/lazyassets"

Package lazyassets registers, fingerprints, and serves application assets.

Types

type Asset

type Asset struct {
	Path		string	`json:"path"`
	Permanent	string	`json:"permanent,omitempty"`
	ContentType	string	`json:"content_type,omitempty"`
	Size		int64	`json:"size"`
	Hash		string	`json:"hash,omitempty"`
	ETag		string	`json:"etag,omitempty"`
	Integrity	string	`json:"integrity,omitempty"`
	Source		string	`json:"source,omitempty"`
	Generated	bool	`json:"generated,omitempty"`
	Ignored		bool	`json:"ignored,omitempty"`
	// contains filtered or unexported fields
}
func (a *Asset) Open
func (a *Asset) Open() (io.ReadCloser, error)

type Option

type Option func(*Options)
func WithBaseURL

WithBaseURL makes helpers return absolute asset URLs while keeping request routing and storage keys path-based.

func WithBaseURL(baseURL string) Option
func WithCSSURLRewrite
func WithCSSURLRewrite(enabled bool) Option
func WithCachePolicies
func WithCachePolicies(logical, permanent CachePolicy) Option
func WithHashLength
func WithHashLength(length int) Option
func WithMaxAssetSize
func WithMaxAssetSize(size int64) Option
func WithOversizePolicy
func WithOversizePolicy(policy OversizePolicy) Option
func WithURLPrefix
func WithURLPrefix(prefix string) Option

type Registry

type Registry struct {
	// contains filtered or unexported fields
}
func New
func New(options ...Option) *Registry
func (r *Registry) Add
func (r *Registry) Add(path string, content []byte, options ...AssetOption) error
func (r *Registry) AddFS
func (r *Registry) AddFS(files fs.FS, options ...SourceOption) error
func (r *Registry) AddReader
func (r *Registry) AddReader(path string, open OpenFunc, options ...AssetOption) error
func (r *Registry) Empty
func (r *Registry) Empty() bool
func (r *Registry) Handler
func (r *Registry) Handler(next http.Handler) http.Handler
func (r *Registry) Helpers
func (r *Registry) Helpers() map[string]any
func (r *Registry) Integrity
func (r *Registry) Integrity(assetPath string) (string, error)
func (r *Registry) Manifest
func (r *Registry) Manifest() Manifest
func (r *Registry) MustPath
func (r *Registry) MustPath(assetPath string) string
func (r *Registry) Path
func (r *Registry) Path(assetPath string) (string, error)
func (r *Registry) ServeHTTP
func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (r *Registry) Unpack
func (r *Registry) Unpack(dir string, options ...UnpackOption) error
func (r *Registry) Upload

Upload writes registered assets to object storage.

The default mode writes only permanent content-hashed paths plus manifest.json, which is the usual shape for CDN or static-file ingress deployments.

func (r *Registry) Upload(ctx context.Context, storage lazystorage.Writer, options ...UploadOption) error