Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Forked from nanmu42/openinbrowser.go
Created June 9, 2022 07:46
Show Gist options
  • Save vadviktor/5a3c57cb642feacedd8158f13f260ecd to your computer and use it in GitHub Desktop.
Save vadviktor/5a3c57cb642feacedd8158f13f260ecd to your computer and use it in GitHub Desktop.
Golang: Open URL in Browser
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