Skip to content

Instantly share code, notes, and snippets.

@huruji
Forked from hyg/gist:9c4afcd91fe24316cbf0
Last active December 20, 2021 06:34
Show Gist options
  • Save huruji/2d26f4d18436e43fbd8092fe5b0e2a49 to your computer and use it in GitHub Desktop.
Save huruji/2d26f4d18436e43fbd8092fe5b0e2a49 to your computer and use it in GitHub Desktop.
在golang中打开浏览器
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