Skip to content

Instantly share code, notes, and snippets.

@alimsk
Forked from hyg/gist:9c4afcd91fe24316cbf0
Last active January 2, 2022 06:05
Show Gist options
  • Save alimsk/6fd4d7ff744b1ace2676cdb6533b84f8 to your computer and use it in GitHub Desktop.
Save alimsk/6fd4d7ff744b1ace2676cdb6533b84f8 to your computer and use it in GitHub Desktop.
open browser in golang
import ("os/exec"; "runtime"; "fmt")
func openBrowser(url string) error {
switch runtime.GOOS {
case "linux", "android":
// termux supports xdg-open
return exec.Command("xdg-open", url).Run()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Run()
case "darwin":
return exec.Command("open", url).Run()
default:
return fmt.Errorf("unsupported platform")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment