openBrowser opens the specified URL in the default browser.
(url string)
| 9 | |
| 10 | // openBrowser opens the specified URL in the default browser. |
| 11 | func openBrowser(url string) error { |
| 12 | var cmd string |
| 13 | var args []string |
| 14 | |
| 15 | switch runtime.GOOS { |
| 16 | case "darwin": |
| 17 | cmd = "open" |
| 18 | args = []string{url} |
| 19 | case "linux": |
| 20 | cmd = "xdg-open" |
| 21 | args = []string{url} |
| 22 | case "windows": |
| 23 | cmd = "rundll32" |
| 24 | args = []string{"url.dll,FileProtocolHandler", url} |
| 25 | default: |
| 26 | return fmt.Errorf("unsupported platform: %s", runtime.GOOS) |
| 27 | } |
| 28 | |
| 29 | return exec.CommandContext(context.Background(), cmd, args...).Start() //nolint:gosec // intentional: opens user's browser |
| 30 | } |