0
go1.8실행 app.go는 항상 백그라운드에서 실행됩니다.
다음과 같이 항상 백그라운드에서 실행되는 방법은 무엇입니까? 나는 파일 server.go 명명하고 "go run server.go
"
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)
}
VS 코드 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
}
]
}
업데이트를하고있다 : 나는 VS 코드 터미널에서이 오류를 얻을 :
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
go 프로그램을 "백그라운드에서 실행"하는 방법은 없습니다. 너 스스로 그렇게해야 해. – JimB
그것은 이상합니다. 나는 VS Code와 dlv의 버그라고 생각한다. –
아니요, 안심 하셔도됩니다. Go 프로그램은 다중 스레드되어 있으며 자체적으로 포크 할 수 없습니다. 더 즉시 종료 될 가능성이 높습니다.'http.ListenAndServe'에서 반환 된 오류를 확인 했습니까? – JimB