Last active
September 5, 2019 13:10
-
-
Save stormwy/10b206c743aa44a1a83935f16dac6e32 to your computer and use it in GitHub Desktop.
[go] open a browser to visit the specify url
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
| package main | |
| import( | |
| "os/exec" | |
| "runtime" | |
| ) | |
| func startBrowser(url string) bool { | |
| // try to start the browser | |
| 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 | |
| } | |
| func main() { | |
| startBrowser("https://www.baidu.com") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment