Created
June 19, 2014 09:36
-
Star
(166)
You must be signed in to star a gist -
Fork
(27)
You must be signed in to fork a gist
-
-
Save hyg/9c4afcd91fe24316cbf0 to your computer and use it in GitHub Desktop.
open browser in golang
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
func openbrowser(url string) { | |
var err error | |
switch runtime.GOOS { | |
case "linux": | |
err = exec.Command("xdg-open", url).Start() | |
case "windows": | |
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() | |
case "darwin": | |
err = exec.Command("open", url).Start() | |
default: | |
err = fmt.Errorf("unsupported platform") | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exec.Command("cmd", "/c", "start", <URL>).Start()
for me it seem nicer and more casual thanexec.Command("rundll32", "url.dll,FileProtocolHandler", <URL>)
if anyone knows any downside tocmd
andstart
approach, pleas letlet me know...