Created
February 25, 2016 18:55
-
-
Save threeaccents/607f3bc3a57a2ddd9d57 to your computer and use it in GitHub Desktop.
open chrome browser with golang function
This file contains hidden or 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 | |
} |
strings.Replace(url, "&", "^&", -1)
hi where did u put that please can u provide a snippet ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If multiple browsers are installed on the system(chrome, chromium etc.), does it must to specify the browser installation path?