Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang run on Windows without deal with the Firewall

I'm working on a Rest API with Go, but everytime I try to run my application with

go run main.go

the Windows Firewall tells me that has blocked some features of my app. I would like to know if there's some way to make my executions without have to Accept everytime.

like image 679
hestellezg Avatar asked Mar 16 '19 21:03

hestellezg


2 Answers

Change

http.ListenAndServe(":3000", r)

to

http.ListenAndServe("127.0.0.1:3000", r)
like image 158
jeffasante Avatar answered Nov 13 '22 23:11

jeffasante


If you are calling go run main.go following is happening:

  • your programm is compiled inside a temporary folder
  • the compiled binary is executed

But the temporary folder is just for one execution. So the next time when you run your programm via go run another folder is used.

The windows firewall does give you always the information which path your server has and if you remember the paths after each time you will see that there is always a different path.

The windows firewall is so configuread that it remembers the path of each programm. So when the path is changing you will always need to comfirm that the new path is allowed to run on that port.

To fix this you should compile your server. Just run go build and exeute the binaries then inside you project folder. Then you will just have to accept just one time.

like image 19
apxp Avatar answered Nov 13 '22 22:11

apxp