Skip to content

Instantly share code, notes, and snippets.

@stormwy
Last active September 5, 2019 13:10
Show Gist options
  • Select an option

  • Save stormwy/10b206c743aa44a1a83935f16dac6e32 to your computer and use it in GitHub Desktop.

Select an option

Save stormwy/10b206c743aa44a1a83935f16dac6e32 to your computer and use it in GitHub Desktop.
[go] open a browser to visit the specify url
package main
import(
"os/exec"
"runtime"
)
func startBrowser(url string) bool {
// try to start the browser
var args []string
switch runtime.GOOS {
case "darwin":
args = []string{"open"}
case "windows":
args = []string{"cmd", "/c", "start"}
default:
args = []string{"xdg-open"}
}
cmd := exec.Command(args[0], append(args[1:], url)...)
return cmd.Start() == nil
}
func main() {
startBrowser("https://www.baidu.com")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment