package lazypwa ¶
import "golazy.dev/lazypwa"
Constants ¶
const LazyDevPWAPath ¶
LazyDevPWAPath is the app control-plane path for PWA state.
const LazyDevPWAPath = "/pwa"
Functions ¶
func RegisterLazyDevHandlers ¶
RegisterLazyDevHandlers registers PWA inspection endpoints.
func RegisterLazyDevHandlers(controlPlane *lazycontrolplane.ControlPlane, app *App)
Types ¶
type App ¶
App is a configured PWA integration.
type App struct {
// contains filtered or unexported fields
}
func New ¶
New creates a PWA integration and registers generated assets/workers.
func New(config Config, opts ...Option) (*App, error)
func (app *App) Enabled ¶
Enabled reports whether the App has active PWA behavior.
func (app *App) Enabled() bool
func (app *App) Handler ¶
Handler serves generated PWA metadata and falls through to next for misses.
func (app *App) Handler(next http.Handler) http.Handler
func (app *App) Helpers ¶
Helpers returns lazyview-compatible PWA helpers.
func (app *App) Helpers() map[string]any
func (app *App) MiddlewareName ¶
MiddlewareName returns the dispatcher-visible middleware name.
func (app *App) MiddlewareName() string
func (app *App) ServeHTTP ¶
ServeHTTP serves generated PWA metadata as a standalone handler.
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (app *App) State ¶
State returns the lazydev-visible PWA state.
func (app *App) State() State
type Config ¶
Config describes an app's progressive web app behavior.
type Config struct {
Installable bool
Version string
ManifestPath string
ServiceWorkerName string
ServiceWorkerPath string
CacheManifestPath string
ClientAssetPath string
Manifest ManifestConfig
Offline OfflineConfig
Push PushConfig
}
func (config Config) IsEnabled ¶
IsEnabled reports whether config enables any PWA behavior.
func (config Config) IsEnabled() bool
type Icon ¶
Icon describes one web app manifest icon.
type Icon struct {
Src string `json:"src"`
Sizes string `json:"sizes,omitempty"`
Type string `json:"type,omitempty"`
Purpose string `json:"purpose,omitempty"`
}
type ManifestConfig ¶
ManifestConfig describes the generated web app manifest.
type ManifestConfig struct {
Name string
ShortName string
Description string
StartURL string
Scope string
Display string
ThemeColor string
BackgroundColor string
Orientation string
Categories []string
Icons []Icon
}
type OfflineConfig ¶
OfflineConfig controls opt-in offline caching.
type OfflineConfig struct {
Enabled bool
URLs []string
Assets []string
Sources []OfflineSource
FallbackURL string
IncludeAssets bool
}
type OfflineSource ¶
OfflineSource supplies URLs for the offline cache manifest.
type OfflineSource interface {
OfflineURLs() ([]string, error)
}
type OfflineSourceFunc ¶
OfflineSourceFunc adapts a function into an OfflineSource.
type OfflineSourceFunc func() ([]string, error)
func (fn OfflineSourceFunc) OfflineURLs ¶
OfflineURLs calls fn.
func (fn OfflineSourceFunc) OfflineURLs() ([]string, error)
type OfflineState ¶
OfflineState describes offline cache configuration.
type OfflineState struct {
Enabled bool `json:"enabled"`
URLs int `json:"urls"`
Fallback string `json:"fallback,omitempty"`
}
type Option ¶
Option configures New.
type Option func(*options)
func WithAppName ¶
WithAppName supplies the lazyapp.Config.Name fallback for manifest names.
func WithAppName(name string) Option
func WithAssets ¶
WithAssets lets lazypwa add its browser client and resolve asset URLs.
func WithAssets(registry *lazyassets.Registry) Option
func WithVersion ¶
WithVersion supplies the application build version fallback.
func WithVersion(version string) Option
func WithWorkers ¶
WithWorkers registers the PWA service worker in registry.
func WithWorkers(registry *lazyworkers.Registry) Option
type PushConfig ¶
PushConfig describes browser push subscription support.
type PushConfig struct {
Enabled bool
ApplicationKey string
SubscriptionPath string
Store SubscriptionStore
Sender PushSender
}
type PushMessage ¶
PushMessage is an application notification payload.
type PushMessage struct {
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
type PushSender ¶
PushSender sends a notification to a subscription.
type PushSender interface {
SendPush(context.Context, PushSubscription, PushMessage) error
}
type PushState ¶
PushState describes push notification configuration.
type PushState struct {
Enabled bool `json:"enabled"`
ApplicationKey bool `json:"application_key"`
Store bool `json:"store"`
Sender bool `json:"sender"`
}
type PushSubscription ¶
PushSubscription is the browser PushSubscription shape applications store.
type PushSubscription struct {
Endpoint string `json:"endpoint"`
ExpirationTime *int64 `json:"expirationTime,omitempty"`
Keys map[string]any `json:"keys,omitempty"`
UserKey string `json:"user_key,omitempty"`
}
type State ¶
State is the lazydev-visible PWA state.
type State struct {
Enabled bool `json:"enabled"`
Installable bool `json:"installable"`
Version string `json:"version,omitempty"`
ManifestPath string `json:"manifest_path,omitempty"`
ServiceWorkerName string `json:"service_worker_name,omitempty"`
ServiceWorkerPath string `json:"service_worker_path,omitempty"`
CacheManifestPath string `json:"cache_manifest_path,omitempty"`
ClientAssetPath string `json:"client_asset_path,omitempty"`
Offline OfflineState `json:"offline"`
Push PushState `json:"push"`
ServiceWorker *lazyworkers.Worker `json:"service_worker,omitempty"`
}
type SubscriptionStore ¶
SubscriptionStore stores browser push subscriptions.
type SubscriptionStore interface {
SavePushSubscription(context.Context, PushSubscription) error
DeletePushSubscription(context.Context, string) error
}
Package lazypwa makes GoLazy applications installable as progressive web apps.
The package owns web app manifest rendering, a small browser client, version-aware service-worker generation, opt-in offline cache manifests, and push-notification contracts. It uses lazyworkers for service-worker registration so applications can register additional workers without making PWA the only worker entrypoint.
Conventional applications configure this package through lazyapp.Config.PWA. Direct users can create an App with New, register its worker in a lazyworkers.Registry, install its Helpers into a renderer, and mount its Handler in any net/http stack.