watcher

package module
v0.0.0-...-0d6303f Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2015 License: MIT Imports: 15 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.

File change event listening infrastructure depends on stable version (.v1) of fsnotify

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

If not added please append your go/bin folder to PATH environment variable.

Usage

cd /path/to/myapp

Start watcher:

watcher

Watcher works like your native binary package. You can pass all the arguments that you are currently using.

Current app usage

myapp -c config -p 7000 -h localhost

With watcher

watcher -c config -p 7000 -h localhost

When you run the command it starts watching folders recursively, starting from the current working directory. It only watches .go and .tmpl files and ignores hidden folders.

Package dependency

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

When your GOPATH is set, you can run your apps via their package names with -run parameter. By default it watches the underlying folder with subfolders.

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

For the cases where your app depends on a few packages that are still in development, and you want to watch all the changes including those packages, you can pass a different package name for watching with -watch parameter.

Micro management of the watched packages are not supported yet. So you cannot exclude any folders.

Author

License

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

Documentation

Overview

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

func SetLog

func SetLog(l Log)

Set the logger used by the package. This isn't thread safe. Only call it before starting any watcher.

Types

type Builder

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

func NewBuilder

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

func (*Builder) Build

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

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

type Log

type Log interface {
	Printf(string, ...interface{})
	Fatalf(string, ...interface{})
}

type Params

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

func NewParams

func NewParams() *Params

NewParams creates a new instance of Params and returns the pointer

func PrepareArgs

func PrepareArgs(args []string) (*Params, error)

PrepareArgs filters the system parameters from package parameters and returns Params instance

func (*Params) CloneRun

func (p *Params) CloneRun()

CloneRun copies run parameter value to watch parameter in-case watch parameter does not exist

func (*Params) Get

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

Get returns the watcher parameter with given name

func (*Params) GetPackage

func (p *Params) GetPackage() string

type Runner

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

Runner listens change events and depending on that kills the obsolete process, and runs the 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)

Init 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, error)

MustRegisterWatcher creates a new Watcher and starts listening given folders

func (*Watcher) Close

func (w *Watcher) Close()

Close closes the fsnotify watcher channel

func (*Watcher) Wait

func (w *Watcher) Wait() <-chan bool

func (*Watcher) Watch

func (w *Watcher) Watch() error

Watch listens file updates, and sends signal to update channel when go 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