Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("already running")
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application represents a running application that will be rebuilt and restarted as files change.
func New ¶
func New(builder Builder, watcher Watcher, logger *slog.Logger) *Application
New creates a new Application with the given builder and watcher. The default target port is ":3000" but can be overridden via `WithTargetAddr`.
func (*Application) ListenAndProxy ¶
Start starts the application and listens for changes, rebuilding and restarting the target application in the background.
func (*Application) Started ¶
func (app *Application) Started() <-chan struct{}
Started returns a channel that will be closed when the application has started.
type BasicBuilder ¶
type BasicBuilder struct { // Bacoff is the function used to calculate the backoff duration between // attempts to start the application. It is called with the number of // attempts so far and should return the number of milliseconds to wait // before the next attempt. Backoff func(attempts int) int // contains filtered or unexported fields }
func NewBuilder ¶
func NewBuilder(buildCmd, runCmd []string, logger *slog.Logger, healthCheck func() bool) *BasicBuilder
NewBuilder returns a new builder that runs the given build and run commands.
func (*BasicBuilder) Build ¶
func (b *BasicBuilder) Build() error
Build builds the application and blocks until the build is complete.
func (*BasicBuilder) ErrorText ¶
func (b *BasicBuilder) ErrorText() string
ErrorText returns the last error text from the build or run commands.
func (*BasicBuilder) Run ¶
func (b *BasicBuilder) Run() error
Run runs the application and returns an error if the application can't start. The function will not return until the application has started and passed the health check.
func (*BasicBuilder) Running ¶
func (b *BasicBuilder) Running() bool
Running returns true if the application is currently running. Running should only be called when holding the lock.
func (*BasicBuilder) Stop ¶
func (b *BasicBuilder) Stop()
Stop should stop the application if it is running. Stop blocks until the application has stopped.
func (*BasicBuilder) WithLock ¶
func (b *BasicBuilder) WithLock(fn func())
WithLock runs the given function while holding a lock so the builder won't restart while the function is running. An sync.RWMutex is used under-the-hood so multiple functions can run at the same time.
type Builder ¶
type Builder interface { // Build builds the application and blocks until the build is complete. Build() error // Run runs the application and returns an error if the application can't // start. This should not block. Run() error // Stop should stop the application if it is running. Stop should block until // the application has stopped. Stop() // Running returns true if the application is currently running. Running() bool // ErrorText returns the error text from the last build or run so it can be // displayed to the user. ErrorText() string // WithLock runs the given function while holding a lock so the builder // won't stop when the function is running. WithLock(func()) }