Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can golang hot swap in develop mode?

Tags:

go

For production environment, I can accept that golang can not hot swap. But for development mode, must I recompile whole project, and restart server, even just modify 1 line of code? Is there any way to quickly hot swap code to check result for debugging?

like image 490
Zhang Buzz Avatar asked Jun 10 '18 02:06

Zhang Buzz


1 Answers

You use or create a watcher process that looks for changes, will recompile and restart the server when it identifies a change.

Here are some examples of this. I use Beego and bee rebuilds my server during development all the time.

Gin

  • GitHub: https://github.com/codegangsta/gin

gin is a simple command line utility for live-reloading Go web applications. Just run gin in your app directory and your web app will be served with gin as a proxy. gin will automatically recompile your code when it detects a change. Your app will be restarted the next time it receives an HTTP request.

Fresh

  • GitHub: https://github.com/pilu/fresh

Fresh will watch for file events, and every time you create/modify/delete a file it will build and restart the application. If go build returns an error, it will log it in the tmp folder.

Fresh works specifically with Traffic, Martini and gocraft/web.

Beego bee

The Beego web framework also does this. This is implemented in bee, a CLI tool for running Beego.

  • Website: https://beego.me/
  • Framework: https://github.com/astaxie/beego/
  • CLI App: https://github.com/beego/bee

bee will watch all the project directories by default and has an option to also watch the vendor directory.

like image 172
Grokify Avatar answered Oct 07 '22 11:10

Grokify