-
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.
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) | |
} | |
} |
I don't know why, but running the above code opens file explorer instead of the browser on my computer.
OS: Windows 10 64bit
Any idea to solve this issue?
typing google.com
or any domain name in the file explorer should open your default browser.
maybe its is not a URL?
I don't know why, but running the above code opens file explorer instead of the browser on my computer.
OS: Windows 10 64bit
Any idea to solve this issue?
Use http or https before urls
nice it work!
@yuansushow idk if it existed when the gist was created but using https://godoc.org/github.com/pkg/browser seem more clean and should works for every golang supported distribution
thank you very much
exec.Command("cmd", "/c", "start", <URL>).Start()
for me it seem nicer and more casual than exec.Command("rundll32", "url.dll,FileProtocolHandler", <URL>)
if anyone knows any downside to cmd
and start
approach, pleas letlet me know...
I don't know why, but running the above code opens file explorer instead of the browser on my computer.
OS: Windows 10 64bit
Any idea to solve this issue?