OpenBrowser opens the provided URL in the default web browser.
(url string)
| 9 | |
| 10 | // OpenBrowser opens the provided URL in the default web browser. |
| 11 | func OpenBrowser(url string) error { |
| 12 | var err error |
| 13 | |
| 14 | browser := os.Getenv("BROWSER") |
| 15 | if browser != "" { |
| 16 | if browser == "none" { |
| 17 | return nil |
| 18 | } |
| 19 | |
| 20 | err = exec.Command(browser, url).Start() |
| 21 | return err |
| 22 | } |
| 23 | |
| 24 | switch runtime.GOOS { |
| 25 | case "linux": |
| 26 | err = exec.Command("xdg-open", url).Start() |
| 27 | case "windows": |
| 28 | err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() |
| 29 | case "darwin": |
| 30 | err = exec.Command("open", url).Start() |
| 31 | default: |
| 32 | err = errors.New("unsupported platform") |
| 33 | } |
| 34 | |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | |
| 39 | return nil |
| 40 | } |
no test coverage detected
searching dependent graphs…