To provide a more structured repo, we also integrated a docker-compose manifest file. Currently it only supports 1.4, 1.5, 1.6, 1.7 at the momentĭocker run -v /path/to/hello:/go/src/hello -e GO_VERSION=1.6 -p 7000:7000 canthefason/go-watcher watcher -run hello
If you want to change the Go version, you can use GO_VERSION environment variable. If you don't set anything, by default Watcher will pick version 1.7. Currently it only supports major versions right now. In the containerized Watcher, our GOPATH is set to /go directory by default, so you need to mount your project to this GOPATH.ĭocker run -v /path/to/hello:/go/src/hello -p 7000:7000 canthefason/go-watcher watcher -run helloĬontainerized Watcher also supports different versions of Go by leveraging gvm.
#Golang filewatcher code#
The most essential thing to run your code in Docker is, mounting your project volume to a container. In our example, we are creating a server that listens to port 7000 and responds to all clients with "watcher is running" string. Let's try to dockerize this example code first. There is an example project under /docker-example directoy. If you want to run Watcher in a containerized local environment, you can achieve this by using canthefason/go-watcher image in Docker Hub. If your intention is making some changes in place, you can set -watch-vendor flag as "true", and start watching vendor directory. Only configuration we have here is, by default we have excluded vendor/ folder from watched directories. 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. Files always must be. The Watcher will return the current file when started. Watcher -c config -run /username/somerootpackagename -watch /username Vendor directory Watcher watches a file and sends changes on the returned channel. Watcher -c config -run /username/somerootpackagenameįor 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. 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). Package dependencyīy default Watcher recursively watches all files/folders under working directory. tmpl files and ignores hidden folders and _test.go files. golang ch Twitter Follow golangch ansible aws lambda books ci concurrency container devops distributed system docker event framework generics golang job golang jobs golang library golang tutorial graphql gui kubernetes libraries library linter markdown memory management messaging mongodb monitoring mySQL nats nodeJS opensource poll proxy. When you run the command, Watcher starts watching folders recursively, starting from the current working directory. Myapp -c config -p 7000 -h localhost With watcherĪs you can see nothing changed between these two calls. You can pass all your existing package arguments to the Watcher, which really lowers the learning curve of the package, and makes it practical. Watcher works like your native package binary.
#Golang filewatcher install#
Go install /canthefason/go-watcher/cmd/watcherĪfter this step, please make sure that your go/bin folder is appended to PATH environment variable. With Watcher, we aimed simplicity in configuration, and tried to make it as simple as possible. 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.
go file changes, and restarting the app in case of an update/delete/add operation. Close: it removes all watches and closes the events channel.įunction NewWatcher establishes a new watcher with the underlying OS and waits for events.Watcher is a command line tool inspired by fresh and used for watching.Remove: it stops watching the named file or directory (non-recursively).Add: it starts watching the named file or directory (non-recursively).type Event struct func (w * Watcher) Add(name string) error func (w * Watcher) Remove(name string) error func (w * Watcher) Close() error The function String() returns a string representation of the event in the form “file: REMOVE|WRITE|…”. The event struct represents a single file system notification. Let’s get familiar with all the types of fsnotify tools.