how to auto reload golang for developer

 issue :

every code changed I have to re run my code with command

go run main.go 

or 

go run .


solution:

now I have a trick to make golang autoreload automatically and it proved it work without any problem than other method I tried

solustion 1

using air actually you can use program from air for more detail you can search on google with keyword "golang air autoreload"

but when I use it I found a problem that my program sometime cannot run perfecly because used port

best solution 

for me best solution is using nodemon from nodejs 

first step you have to install nodejs from here

https://nodejs.org/en/download/

youcan install msi for windows and install it on your computer

if you have installed it you have to install tool name nodemon with open your command prompt

npm install -g nodemon

now you can use 

nodemon -e go --exec go run .

it mean nodemon will watch your file with extention .go , if any changes it will reload your program

and this solution is best for me

for more simple you can create bat file which contain that command and put it like this


now when you developing your golang application just type on your command prompt

run.bat



Comments