Skip to content

Instantly share code, notes, and snippets.

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