diff --git a/main.go b/main.go index 0e920dd..b5830e1 100644 --- a/main.go +++ b/main.go @@ -9,19 +9,26 @@ import ( ) func main() { - go func() { - server.Run() - }() - - chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" - cmd := exec.Command(chromePath, "--app=http://127.0.0.1:27149/static/index.html") - cmd.Start() - - chSingal := make(chan os.Signal, 1) - signal.Notify(chSingal, os.Interrupt) + go server.Run() + cmd := startBrowser() + chSingal := listen2Interrupt() select { case <-chSingal: cmd.Process.Kill() } } + +func startBrowser() *exec.Cmd { + chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" + cmd := exec.Command(chromePath, "--app=http://127.0.0.1:27149/static/index.html") + cmd.Start() + return cmd +} + +//监听中断信号 +func listen2Interrupt() chan os.Signal { + chSignal := make(chan os.Signal, 1) + signal.Notify(chSignal, os.Interrupt) + return chSignal +}