Skip to content

Instantly share code, notes, and snippets.

@0xcafed00d
Last active May 14, 2016 10:08
Show Gist options
  • Save 0xcafed00d/fbfe473ae41c69fd1bd7 to your computer and use it in GitHub Desktop.
Save 0xcafed00d/fbfe473ae41c69fd1bd7 to your computer and use it in GitHub Desktop.
start browser in from go
/ startBrowser tries to open the URL in a browser
// and reports whether it succeeds.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment