package util import ( "fmt" "os/exec" "runtime" ) var commonds = map[string]string{ "windows": "cmd /c start", "darwin": "open", "linux": "xdg-open", } //OpenUrl 调用系统命令打开浏览器 func OpenUrl(url string) error { run, ok := commonds[runtime.GOOS] if !ok { return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS) } cmd := exec.Command(run, url) //拼凑命令: cmd /c start https://baidu.com return cmd.Start() }