重构main: 更合理

master
ZGGSONG 3 years ago
parent c09e6f186b
commit 566eb0ce05

@ -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
}

Loading…
Cancel
Save