watcher

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2016 License: MIT Imports: 16 Imported by: 0

README

Watcher GoDoc Build Status

Watcher is a command line tool inspired by fresh and used for watching .go file changes, and restarting the app in case of an update/delete/add operation.

Most of the existing file watchers have a configuration burden, and even though Go has a really short build time, this configuration burden makes your binaries really hard to run right away. With Watcher, we aimed simplicity in configuration, and tried to make it as simple as possible.

Installation

Get the package with:

go get github.com/canthefason/go-watcher

Install the binary under go/bin folder:

go install github.com/canthefason/go-watcher/cmd/watcher

After this step, please make sure that your go/bin folder is appended to PATH environment variable.

Usage

cd /path/to/myapp

Start watcher:

watcher

Watcher works like your native package binary. You can pass all your existing package arguments to the Watcher, which really lowers the learning curve of the package, and makes it practical.

Current app usage

myapp -c config -p 7000 -h localhost

With watcher

watcher -c config -p 7000 -h localhost

As you can see nothing changed between these two calls. When you run the command, Watcher starts watching folders recursively, starting from the current working directory. It only watches .go and .tmpl files and ignores hidden folders and _test.go files.

Package dependency

By default Watcher recursively watches all files/folders under working directory. If you prefer to use it like go run, you can call watcher with -run flag anywhere you want (we assume that your GOPATH is properly set).

watcher -c config -run github.com/username/somerootpackagename

For the cases where your main function is in another directory other than the dependant package, you can do this by passing a different package name to -watch parameter.

watcher -c config -run github.com/username/somerootpackagename -watch github.com/username

Vendor directory

Since Globs and some optional folder arrays will make it harder to configure, we are not planning to have support for a configurable watched folder structure. Only configuration we have here is, by default we have excluded vendor/ folder from watched directories. If your intention is making some changes in place, you can set -watch-vendor flag as "true", and start watching vendor directory.

Author

License

The MIT License (MIT) - see LICENSE.md for more details

Documentation

Overview

Package watcher is a command line tool inspired by fresh (https://github.com/pilu/fresh) and used for watching .go file changes, and restarting the app in case of an update/delete/add operation. After you installed it, you can run your apps with their default parameters as: watcher -c config -p 7000 -h localhost

Package watcher watches all file changes via fsnotify package and sends update events to builder

Index

Constants

This section is empty.

Variables

View Source
var ErrPathNotSet = errors.New("gopath not set")

GoPath not set error

Functions

This section is empty.

Types

type Builder

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

Builder composes of both runner and watcher. Whenever watcher gets notified, builder starts a build process, and forces the runner to restart

func NewBuilder

func NewBuilder(w *Watcher, r *Runner) *Builder

NewBuilder constructs the Builder instance

func (*Builder) Build

func (b *Builder) Build(p *Params)

Build listens watch events from Watcher and sends messages to Runner when new changes are built.

type Params

type Params struct {
	// Package parameters
	Package []string
	// Go-Watcher parameters
	Watcher map[string]string
}

Params is used for keeping go-watcher and application flag parameters

func NewParams

func NewParams() *Params

NewParams creates a new Params instance

func ParseArgs added in v0.2.0

func ParseArgs(args []string) *Params

ParseArgs extracts the application parameters from args and returns Params instance with separated watcher and application parameters

func (*Params) Get

func (p *Params) Get(name string) string

Get returns the watcher parameter with the given name

type Runner

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

Runner listens for the change events and depending on that kills the obsolete process, and runs a new one

func NewRunner

func NewRunner() *Runner

NewRunner creates a new Runner instance and returns its pointer

func (*Runner) Close

func (r *Runner) Close()

func (*Runner) Run

func (r *Runner) Run(p *Params)

Run initializes runner with given parameters.

func (*Runner) Wait

func (r *Runner) Wait()

type Watcher

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

Watcher watches the file change events from fsnotify and sends update messages. It is also used as a fsnotify.Watcher wrapper

func MustRegisterWatcher

func MustRegisterWatcher(params *Params) *Watcher

MustRegisterWatcher creates a new Watcher and starts listening to given folders

func (*Watcher) Close

func (w *Watcher) Close()

Close closes the fsnotify watcher channel

func (*Watcher) Wait

func (w *Watcher) Wait() <-chan struct{}

Wait waits for the latest messages

func (*Watcher) Watch

func (w *Watcher) Watch()

Watch listens file updates, and sends signal to update channel when .go and .tmpl files are updated

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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