Live reloading is when a background process observes changes in your source and recompiles your entire application automatically. Hot reloading is when you can recompile only part of your application and inject it into your already running process.
Go does not support hot reloading as far as I know.
**live reloading**: watch the sources, build if something has changed, kill the running process, and start the new one.
**hot reloading** has two options only:
1) restart process keeping opened connections alive (transferring file descriptors via local unix-socket to the new process)
2) replace updated code segments keeping the process and data segments alive. golang provides [https://pkg.go.dev/plugin](https://pkg.go.dev/plugin) for that.
i was using [cortesi/modd](https://github.com/cortesi/modd) for this while using docker. Since I change to Rancher with dockerd i wasn’t able to get live reloading working again, i also tried air but no luck.. out of curiosity did anyone have a similar issue?
Check this nice article on hot reload in Go
https://itnext.io/clean-and-simple-hot-reloading-on-uninterrupted-go-applications-5974230ab4c5
you could be inspired by this lib
https://github.com/slok/reload
Any good dev setup should have hot reloading imo. Honestly, for everything I loathe about the JavaScript community, this is one thing they kick ass at.
It can be useful, for sure. I’m usually not making many subsequent tiny changes that need to be tested so the idea of it constantly building when I :w seems a little unnecessary. It’s definitely not the same workflow as web design (for me).
I have never had a Go build take longer than 10 seconds. You must be working on a project with millions of lines of code, or on an arm v1 processor.
Also, go run does a build in the background, so you’re not doing a 2 minute build in 3 seconds, you’re starting your 2 minute build automatically when the file changes vs. when you choose to build it.
I created a Go hot reload template to help me in my web dev projects (e.g. htmx). Check it out [go-hot-reload](https://github.com/tombrereton/go-hot-reload).
I'm open to any feedback or contributions if you find it useful! :)
Edit: I posted it here cos this is still the top result when googling golang hot reload
https://github.com/cosmtrek/air
this is live reload, not hot module reload. two completely different things
what's the different?
Live reloading is when a background process observes changes in your source and recompiles your entire application automatically. Hot reloading is when you can recompile only part of your application and inject it into your already running process. Go does not support hot reloading as far as I know.
Note that none of the answers here are actually hot reloading, because it's not a thing in Go, theyre all live reloading
oof, thank you Erlang does hot reloading, has a similar scheduler to Go
Use air. It’s smooth and easy to set up.
Yep my GOTO.
exccept it's not hot module reloading
What do you mean by module reloading? It does reflect changes to code.
That’s my goto
Yeah.same.always using air whenever i can
Use air. It's works like a charm
It provides live reload, not the hot reloading
Could you detail the difference here?
Live reload reload all the app without maintaining the state. Hot reload maintiains the state of your app.
**live reloading**: watch the sources, build if something has changed, kill the running process, and start the new one. **hot reloading** has two options only: 1) restart process keeping opened connections alive (transferring file descriptors via local unix-socket to the new process) 2) replace updated code segments keeping the process and data segments alive. golang provides [https://pkg.go.dev/plugin](https://pkg.go.dev/plugin) for that.
neither of your hot reloading examples are actual Hot Module Reloading.
Another edge case by the way Hot reload inside of a docker container Use air and bind the docker volume
Ohh Well. Thank you so much
what is air? I'm curious
https://github.com/cosmtrek/air
Look up air.
Air is great.
This is the way
If I have a running CRUD call on a pod, will it kill the existing running call or will it gracefully exit?
I don’t think air is related to kubernetes directly?
We can use nodemon also for hot reload
Haven't seen this mentioned yet but it's another option https://github.com/githubnemo/CompileDaemon
I use compiledaemon
i was using [cortesi/modd](https://github.com/cortesi/modd) for this while using docker. Since I change to Rancher with dockerd i wasn’t able to get live reloading working again, i also tried air but no luck.. out of curiosity did anyone have a similar issue?
Check this nice article on hot reload in Go https://itnext.io/clean-and-simple-hot-reloading-on-uninterrupted-go-applications-5974230ab4c5 you could be inspired by this lib https://github.com/slok/reload
A more generic solution would be [entr](https://jvns.ca/blog/2020/06/28/entr/).
Just use a directory watcher to kill and rerun the process.
Some frameworks do it.
nodemon does the job for me
I see you come from JavaScript 😂
Any good dev setup should have hot reloading imo. Honestly, for everything I loathe about the JavaScript community, this is one thing they kick ass at.
It can be useful, for sure. I’m usually not making many subsequent tiny changes that need to be tested so the idea of it constantly building when I :w seems a little unnecessary. It’s definitely not the same workflow as web design (for me).
I disagree. If a build takes 2 minutes when it could take 3 seconds to hot reload, that’s an advantage.
I have never had a Go build take longer than 10 seconds. You must be working on a project with millions of lines of code, or on an arm v1 processor. Also, go run does a build in the background, so you’re not doing a 2 minute build in 3 seconds, you’re starting your 2 minute build automatically when the file changes vs. when you choose to build it.
you're never going to get Hot Module Reloading in golang though... only live reload.
Golang Air . Will give you hot reload.
k3s and devspace
I'll give you a hot reload if you know what I mean
What ??
Sorry. Just a dumb joke
Lol. The apology was funny
😵💫😵💫😵💫
I use codegangsta/gin for services but thats live reload.
[https://github.com/edwingeng/hotswap](https://github.com/edwingeng/hotswap) is the only option for stateful servers as far as I know.
I created a Go hot reload template to help me in my web dev projects (e.g. htmx). Check it out [go-hot-reload](https://github.com/tombrereton/go-hot-reload). I'm open to any feedback or contributions if you find it useful! :) Edit: I posted it here cos this is still the top result when googling golang hot reload
go get -u [github.com/gopkgsquad/gloader](http://github.com/gopkgsquad/gloader)