Reputation: 25974
I have a simple HTTP server, and I want to run it as a process in the background.
my server.go file is like:
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there X, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
And I run: go run server.go
VS Code Launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
}
]
}
Update: I get this error in VS Code Terminal:
2017/04/07 16:41:41 debugger.go:257: created breakpoint: &api.Breakpoint{ID:1, Name:"", Addr:0x12063ef, File:"/Users/X/Documents/X/play/go/server.go", Line:9, FunctionName:"main.handler", Cond:"", Tracepoint:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(nil), LoadLocals:(*api.LoadConfig)(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0}
2017/04/07 16:41:41 debugger.go:412: continuing
Upvotes: 6
Views: 11549
Reputation: 29316
Did you tried running your server using nohup?
nohup go run server.go &
Upvotes: 12