6 ms·
Air – Live reload when developing with Go
- ryanrolds 5y agoUseful tool, but it has some bugs related to consecutive build failures. Restarting Air is required to fix it. I still use it, just wish I didn't have to restart it frequently.
- cirwin 5y agoShameless plug, but I built https://github.com/superhuman/lrt https://github.com/superhuman/lrt as simply as possible, explicitly to avoid this kind of issue (which seem to plague tools in this space).
- mohanmcgeek 5y agoAir also needs be restarted if you're switching git branches and there are a lot of changes between the branches
- xyzzy_plugh 5y agoI've found it simple enough to start a goroutine to watch argv[0] and exec it if it's newer than the startup time of the process. Unlike other languages with insane build and link times, I've never needed this for Go. Builds are nearly instantaneous.
- mohanmcgeek 5y agoThis doesn't watch the fs and build automatically now.. Does it? We started using this tool a couple of months ago. It was a huge productivity boost. We had multiple binaries produced by the build and all had to run to make the complete service
- xyzzy_plugh 5y agoI usually run "go build" to see if my code compiles and respond to the errors. If it builds successfully, it's restarted automatically. I personally don't see value in running "go build" out-of-band in another terminal where I can't easily pipe the errors into my editor (or automatically if I'm running it in the editor). If that works for you, then great.
- leetrout 5y agohttp://eradman.com/entrproject/ http://eradman.com/entrproject/ find . -name "*.go" | entr -r go run my/main/file.go
- thewakalix 5y agoThat can’t handle file creation after the command is run, though, right?
- gavinray 5y agoI'm not sure about "find" -- but I also use "entr" for this (and just about a billion other tasks, is there anything you can't use it for?) and I personally do something like: ls src/**/*.filetype | entr -r -s "some command" And this will catch new files
- maleldil 5y ago`man entr` has an example for dealing with new files using the `-d` option: $ while true; do ls src/*.rb | entr -d make; done
- chrsig 5y agoWhen writing go, I've always found if I find myself constantly restarting & recompiling a program during development, it means that I should be writing tests instead.
- bogota 5y agoYep it’s actually one of the things i love. If waiting for go compile time has gotten to be a problem it is time for tests or to refactor if a test can’t be easily written.
- sodality2 5y agoDoes live-reload that runs tests exist?
- ikiris 5y agothis is just a fancy description for a basic rollout system.
- maddyboo 5y agoIf you write your tests with Ginkgo [0] its CLI can do this for you. It also has nice facilities to quickly disable a test or portion of a test by prepending an X to the test function name, or to focus a test (only run that test) by prepending an F. It’s pretty nice. [0]: https://onsi.github.io/ginkgo/ https://onsi.github.io/ginkgo/
- pjmlp 5y agoYes, on .NET, Visual Studio Enterprise. https://docs.microsoft.com/en-us/visualstudio/test/live-unit-testing?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/test/live-unit...
- dom_hutton 5y agoIf it can watch files and trigger your app to boot it can certainly trigfer the test runner.
- dnautics 5y agoSuppose you want to instrument some code that touches a database, because you suspect some data (in prod) is coming off the database that is messing your assumptions up, but you don't know yet what specific assumption it is. Because it's just a gut feeling, you can't write a test against it
- rckrd 5y agoI built something like this in Go a few years ago but it reloads your infrastructure when it changes, recompiles your code when it needs to, and syncs static files or interpreted files to wherever your app is running (desktop or cloud). Think of it like docker-compose but with file watching + sync + smart rebuilds. https://skaffold.dev/ https://skaffold.dev/
- gavinray 5y agoYou're the author of Skaffold? Damn that's impressive
- __float 5y agoIs there a skaffold for borg that inspired this? Curious if there are any existing things you were inspired by, or particular pitfalls in alternatives you wanted to avoid!
- rckrd 5y agoNo but I heavily drew from three tools: (1) minikube, which I also maintained at Google. I saw how difficult getting started with Kubernetes could be even when you were able to create a local cluster. I also knew all the shortcuts that you could take to streamline local Kubernetes workflows (e.g., loading images directly into the minikube docker daemon). (2) docker compose, which remains a great tool but had no analogue for Kubernetes. It also didn't have a concept of syncing for hot-reloadable projects or built-in file watcher. (1), Draft by the Deis folks at Microsoft, which was a great tool but suffered from having a component that you needed to install on the cluster to work, where the skaffold architecture was purely client side (making it a lot easier to get started, and faster). I also wanted to make skaffold pluggable, so it supported helm, kubectl, docker, bazel, and other tools right from the start. It also had clear boundaries between build and deploy and ideas for CI and gitops workflows built in.
- rejectedandsad 5y agoHow does it handle watch mode for compiled or built code?
- ashishb 5y agoHere's my simple live reload that's generic enough for any language for me ``` filewatcher --immediate --restart "*/*.go" "killall ${BINARY_NAME}; make run" ```
- joseph 5y agoIn my projects I use a script to watch for changes and recompile/restart with a loop such as: executable=/path/to/target while true; do make build if [ ${?} -eq 0 ]; then ${executable} run & pid=${!} fi inotifywait -qq -e create -e modify -e delete --exclude '\.#.*' -r . [ -n "${pid}" ] && kill ${pid}; pid= done This is simplified a bit, as the script usually contains some other things like starting and initializing the database.
- iooi 5y agoWe use watchman with our Go apps: https://facebook.github.io/watchman/docs/install.html https://facebook.github.io/watchman/docs/install.html It's straightforward to use but also has a ton of options so you can do whatever you want with it. It also handles common issues you'll run into when working with larger codebases where you end up watching over too many files. And finally, it has configuration files so you can have the same setup as the rest of the engineers on your team. More importantly, it's actively maintained and has been out for a while, and it's not specific to Go apps: you can use it for anything you want to watch and execute on.
- hycaria 5y agoI used docker + realize for the exact same task (go + gin) a year ago. Wish I heard of air or skaffold. Didn’t find them when searching around this issue.
- jbub 5y agoI can recommend https://github.com/cortesi/modd https://github.com/cortesi/modd, it seems like its not developed anymore though
- thiht 5y agoThe best tool I’ve found for this job is reflex[1]. It’s easy to setup, Go agnostic, very « UNIX » in its philosophy, doesn’t get in your way with its own logs, and just works. Before that I used realize but it has the bad behavior of always adding it’s own prefix to the logs, which sucks. [1]: https://github.com/cespare/reflex https://github.com/cespare/reflex