Documentation
¶
Index ¶
- type Config
- type Reloader
- func (r *Reloader) CacheMiddleware(handler http.Handler) http.Handler
- func (r *Reloader) Close()
- func (r *Reloader) Enabled() bool
- func (r *Reloader) Handler() http.Handler
- func (r *Reloader) MustParseTemplate(t *template.Template) *template.Template
- func (r *Reloader) Notify()
- func (r *Reloader) ParseTemplate(t *template.Template) (*template.Template, error)
- func (r *Reloader) SetEnabled(enabled bool)
- func (r *Reloader) Start(dir fs.FS)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Logger is the logger used by the notifier.
Logger *slog.Logger
// Route is the HTTP route where the live reload handler is mounted.
Route string
// Enabled indicates whether live reload is enabled.
Enabled bool
// MaxAge is the maximum age for cached assets when live reload is enabled.
MaxAge time.Duration
}
type Reloader ¶
type Reloader struct {
// contains filtered or unexported fields
}
Reloader implements a live reload notifier that broadcasts reload signals to subscribed clients.
func (*Reloader) CacheMiddleware ¶
CacheMiddleware is a middleware that sets Cache-Control headers to enable caching for the specified max age.
func (*Reloader) Close ¶
func (r *Reloader) Close()
Close tears down the notifier and closes every subscriber channel, signalling to callers that no further reload events will arrive.
func (*Reloader) Handler ¶
Handler streams server-sent events that instruct the browser to refresh whenever the dev watcher picks up a change on disk. The SSE connection stays open until the client disconnects or the server shuts down.
func (*Reloader) MustParseTemplate ¶
MustParseTemplate is like ParseTemplate but panics on error.
func (*Reloader) Notify ¶
func (r *Reloader) Notify()
Notify broadcasts a reload signal to every active listener without blocking on slow readers. If a listener already has a pending notification we leave it untouched so it still reloads on its next poll.
func (*Reloader) ParseTemplate ¶
ParseTemplate parses the reload template into the provided template.
func (*Reloader) SetEnabled ¶
SetEnabled sets whether the notifier is currently enabled.