Last active
May 14, 2016 10:08
-
-
Save 0xcafed00d/fbfe473ae41c69fd1bd7 to your computer and use it in GitHub Desktop.
start browser in from go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ 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