Skip to content

Instantly share code, notes, and snippets.

@iilxy
Forked from threeaccents/openbrowser.go
Created June 15, 2018 12:53
Show Gist options
  • Save iilxy/5381636886098b95a9869a20fc657fcd to your computer and use it in GitHub Desktop.
Save iilxy/5381636886098b95a9869a20fc657fcd to your computer and use it in GitHub Desktop.
open chrome browser with golang function
// openBrowser tries to open the URL in a browser,
// and returns whether it succeed in doing so.
func openBrowser(url string) bool {
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