livereload package

import "code.pfad.fr/devf/livereload"

package livereload handles Server-sent events and injection of the livereload script into upstream HTML pages.

To get started, create a Handler struct, serve it as you wish and call ForwardMessages to trigger reloads.

Example

Index

Examples

func SingleLineRequestLogger

SingleLineRequestLogger will print a colored line for each request, for instance:

200 GET /style.css                                                         300µs
Code Method RequestURI                                              ResponseTime

func SlowResponseLogger

SlowResponseLogger will print a colored line for each request when the headers weren't sent within the timeout, for instance:

slow response (>1s)  GET /devf/style.css
RedMessage           Method RequestURI

type Handler

Handler is a wrapper to manage livereloading. Only the Upstream field is required. See SingleLineRequestLogger and SlowResponseLogger for the optional LogRequest and LogSlowResponse fields.

func (*Handler) ForwardMessages

ForwardMessages forwards the non-empty messages to the webpage, to trigger a reload. This method returns when the message channel is closed.

func (*Handler) ServeHTTP

ServeHTTP handles /.devf/* requests and inject the livereload script to html responses of the Upstream http.Handler.

Source Files

handler.go logger.go sse.go