golazy.dev
–
golazy.dev
/
lazyassets
Index
|
Files
package lazyassets ¶
import "golazy.dev/lazyassets"
Constants ¶
const LazyDevAssetsPath ¶
const LazyDevAssetsPath = "/assets"
Functions ¶
func RegisterLazyDevHandlers ¶
RegisterLazyDevHandlers registers asset inventory endpoints.
func RegisterLazyDevHandlers(controlPlane *lazycontrolplane.ControlPlane, registry *Registry)
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 AssetOption ¶
type AssetOption func(*assetOptions)
func AssetSource ¶
func AssetSource(name string) AssetOption
func ContentType ¶
func ContentType(contentType string) AssetOption
func ReplaceAsset ¶
func ReplaceAsset() AssetOption
type CachePolicy ¶
type CachePolicy string
type Manifest ¶
type Manifest struct {
Assets []Asset `json:"assets"`
}
type OpenFunc ¶
type OpenFunc func() (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 WithDevelopmentMode ¶
WithDevelopmentMode serves logical asset paths directly without permanent hashed URLs, cache headers, ETags, integrity values, or CSS URL rewriting.
func WithDevelopmentMode(enabled bool) 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 Options ¶
type Options struct {
URLPrefix string
MaxAssetSize int64
OversizePolicy OversizePolicy
HashLength int
LogicalCache CachePolicy
PermanentCache CachePolicy
RewriteCSSURLs bool
BaseURL string
Development bool
}
type OversizePolicy ¶
type OversizePolicy int
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
type Source ¶
type Source interface {
Assets(*Registry) error
}
type SourceFunc ¶
type SourceFunc func(*Registry) error
func (fn SourceFunc) Assets ¶
func (fn SourceFunc) Assets(registry *Registry) error
type SourceOption ¶
type SourceOption func(*sourceOptions)
func Replace ¶
func Replace() SourceOption
func SourceName ¶
func SourceName(name string) SourceOption
type UnpackMode ¶
type UnpackMode int
type UnpackOption ¶
type UnpackOption func(*unpackOptions)
func WithUnpackMode ¶
func WithUnpackMode(mode UnpackMode) UnpackOption
type UploadOption ¶
type UploadOption func(*uploadOptions)
func WithUploadMode ¶
WithUploadMode selects which asset paths are written to storage.
func WithUploadMode(mode UnpackMode) UploadOption
func WithUploadPrefix ¶
WithUploadPrefix writes assets below prefix in the destination storage.
func WithUploadPrefix(prefix string) UploadOption
func WithoutUploadManifest ¶
WithoutUploadManifest disables writing manifest.json to storage.
func WithoutUploadManifest() UploadOption
Package lazyassets registers, fingerprints, serves, and uploads application assets.
In a GoLazy application, lazyapp registers Public files and generated asset sources into one Registry, installs view helpers such as asset_path and stylesheet, and serves registered files as the final public fallback.
The package is also independently usable for static file serving or deploy preparation. Create a Registry, add filesystem or generated assets, serve it with Handler, or export permanent assets through Upload and a lazystorage writer.