-
-
Save iilxy/5381636886098b95a9869a20fc657fcd to your computer and use it in GitHub Desktop.
open chrome browser with golang function
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
// openBrowser tries to open the URL in a browser, | |
// and returns whether it succeed in doing so. | |
func openBrowser(url string) bool { | |
var args []string | |
switch runtime.GOOS { | |
case "darwin": | |
args = []string{"open"} | |
case "windows": | |
args = []string{"cmd", "/c", "start"} | |
default: | |
args = []string{"xdg-open"} | |
} | |
cmd := exec.Command(args[0], append(args[1:], url)...) | |
return cmd.Start() == nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment