Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smallnest/b2560b6d99fed8c6640f49c3f0ab99d2 to your computer and use it in GitHub Desktop.
Save smallnest/b2560b6d99fed8c6640f49c3f0ab99d2 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