autoreload

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2022 License: Unlicense Imports: 8 Imported by: 1

README

GoDoc

autoreload

autoreload provides a package and a command for automatically reloading an executable when that executable changes. It intended to be used in a local development environment to reload the executable after it has been modified as part of the development process. An example use case, would be to reload a go web app after you have edit the source code and recompiled the executable.

Installation

autoreload can be used as either a package that is integrated into your application or as an executable that you run your application with. To use the package, add the following to your application:

autoreload.New().Start()

See the provided example for greater detail on how to integrate the package into your application.

To use the executable, you must first install it

go install github.com/agschwender/autoreload/autoreloader@v1.0.0

You can then execute it by running the following

autoreloader my-application -v -a --arg

Documentation

Overview

Package autoreload restarts a process if its executable changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCommand

func WithCommand(cmd string) option

WithCommand defines the command executable that AutoReloader should watch. By default, this will be the currently running command.

func WithLogger

func WithLogger(logger Logger) option

WithLogger defines the logger that the AutoReloader will use. By default, it will log using the built-in log package.

func WithMaxAttempts

func WithMaxAttempts(maxAttempts int) option

WithMaxAttempts defines how many times the AutoReloader should attempt to reload the application. By default, this is 10.

func WithOnReload

func WithOnReload(onReload onReloadFunc) option

WithOnReload defines a callback that is executed just prior to reloading the application. This is useful for gracefully shutting down your application.

Types

type AutoReloader

type AutoReloader struct {
	// contains filtered or unexported fields
}

AutoReloader provides functionality for reloading an application.

func New

func New(opts ...option) AutoReloader

New creates a new AutoReloader with the supplied options.

func (AutoReloader) Start

func (ar AutoReloader) Start()

Start launches a goroutine that periodically checks if the modified time of the command has changed. If so, the binary is re-executed with the same arguments. This is a developer convenience and not intended to be started in a production environment.

func (AutoReloader) Stop

func (ar AutoReloader) Stop()

Stop will stop the autoreloader from watching the executable and reloading it.

type Logger

type Logger interface {
	Info(string)
	Fatal(string, error)
}

Logger defines an interface for logging info and fatal errors out of the autoreloader process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL