构建Go应用

I just started learning golang and I want tried to build a hello world webpage as per here.However when I use run or build via SSH i don't "regain" control of the prompt.

enter image description here

If I do Ctrl + C , my app no longer work , I think i am misunderstanding how Go work

Note that if you nohup the process it will run "indefinitely" until you call kill <PID> on it. Further, if it binds to a HTTP port you'll need to remember to kill the running process else your new/rebuilt process won't be able to bind.

Using something simple like Supervisor (guide here) or daemontools is a more sane way to run manage processes. Here's a quick Supervisor config for a Go application:

[program:index]
command=/home/yourappuser/bin/index
autostart=true
autorestart=true
startretries=10
# the user your app should run as (i.e. *not* root!)
user=yourappuser
# where your application runs from
directory=/srv/www/yourapp.com/
# environmental variables
environment=APP_SETTINGS="/srv/www/yourapp.com/prod.env"
redirect_stderr=true
# the name of the log file.
stdout_logfile=/var/log/supervisor/yourapp.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10

This will work if your Go application doesn't need to bind to port 80. If it does, use setcap (and never run your application as root) with setcap cap_net_bind_service=+ep /home/yourappuser/bin/index.

You can use nohup for that like this:

nohup ./index &

nohup used to prevent termination of the process after user logout and & used to start process in background. After it you can exit from console.