Skip to content

Instantly share code, notes, and snippets.

@gustavohenrique
Created November 17, 2021 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavohenrique/80942d5dfa85795310451ee76c653afa to your computer and use it in GitHub Desktop.
Save gustavohenrique/80942d5dfa85795310451ee76c653afa to your computer and use it in GitHub Desktop.
open url golang
func openURL(url string) error {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", "http://localhost:4001/").Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("Cannot open URL %s on this platform", url)
}
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment