dead

package module
v0.0.0-...-ea41c94 Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: MIT Imports: 9 Imported by: 0

README ¶

dead 💀

GoDoc Go Report Card

Dead simple live reloading for Go web servers

Usage

Just add a line of code like in example below:

package main

import (
	"log"
	"net/http"

	"github.com/tomyl/dead"
)

func main() {
	dead.Default().Watch(".", "templates", "server/*").Main()
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Now, if an enviroment variable DEAD (can be changed to something else) is set to watch before starting the binary, Main() will watch the the specified directories forever and re-invoke the binary with cleared ennviroment variable (Main() will return immediately if the value isn't watch).

$ go build
$ DEAD=watch ./mybin

Whenever an .html file is modified in specified directories, the re-invoked process is restarted. If a .go file is modified, go build (can be changed to something else) is executed first.

TODO

  • Make it configurable what extensions to trigger on.
  • Add more documentation.
  • Finish this TODO list.

Documentation ¶

Overview ¶

Package dead makes it easy for web servers to restart on source code or template changes.

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Config ¶

type Config struct {
	// Which environment variable to inspect when checking if we should start watching.
	Env string
	// What directories to watch. Can use glob patterns.
	Patterns []string
	// How long to wait before acting on file modification event.
	Debounce time.Duration
	// What command to execute when building.
	BuildPath string
	BuildArgs []string
}

Config says what directories to watch and what to execute when building.

func Default ¶

func Default() *Config

Default returns a reasonable default config (environment variable DEAD, 500 ms debounce time, run "go build" to build.

func (*Config) Main ¶

func (c *Config) Main()

Main is the watch main loop. Will return immediately if environment variable isn't set to "watch".

func (*Config) Watch ¶

func (c *Config) Watch(patterns ...string) *Config

Watch adds directories to watch for file changes. Can use glob patterns.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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