OpenURL opens the specified URL in the default web browser. It first attempts to use a platform-agnostic library and falls back to platform-specific commands if that fails. Parameters: - url: The URL to open. Returns: - An error if the URL cannot be opened, otherwise nil.
(url string)
| 21 | // Returns: |
| 22 | // - An error if the URL cannot be opened, otherwise nil. |
| 23 | func OpenURL(url string) error { |
| 24 | fmt.Printf("Attempting to open URL in browser: %s\n", url) |
| 25 | |
| 26 | // Try using the open-golang library first |
| 27 | err := open.Run(url) |
| 28 | if err == nil { |
| 29 | log.Debug("Successfully opened URL using open-golang library") |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | log.Debugf("open-golang failed: %v, trying platform-specific commands", err) |
| 34 | |
| 35 | // Fallback to platform-specific commands |
| 36 | return openURLPlatformSpecific(url) |
| 37 | } |
| 38 | |
| 39 | // openURLPlatformSpecific is a helper function that opens a URL using OS-specific commands. |
| 40 | // This serves as a fallback mechanism for OpenURL. |