-
-
Save alimsk/6fd4d7ff744b1ace2676cdb6533b84f8 to your computer and use it in GitHub Desktop.
open browser in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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