Skip to content

Instantly share code, notes, and snippets.

@sedx
Forked from hyg/gist:9c4afcd91fe24316cbf0
Created January 13, 2018 17:35
Show Gist options
  • Save sedx/83c9603be32c906aa8b673749964ed4f to your computer and use it in GitHub Desktop.
Save sedx/83c9603be32c906aa8b673749964ed4f to your computer and use it in GitHub Desktop.
open browser in golang
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment