-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package browser | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
// OpenInBrowser attempts to open the specified URL in the default browser. | ||
// Returns an error if the command fails or the platform is unsupported. | ||
func OpenInBrowser(url string) error { | ||
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 { | ||
return fmt.Errorf("failed to open URL: %w", err) | ||
} | ||
return nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,6 @@ | ||
package utility | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
// ObjecteList contains ID and Name | ||
type ObjecteList struct { | ||
ID, Name string | ||
} | ||
|
||
// OpenInBrowser attempts to open the specified URL in the default browser. | ||
// Returns an error if the command fails or the platform is unsupported. | ||
func OpenInBrowser(url string) error { | ||
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 { | ||
return fmt.Errorf("failed to open URL: %w", err) | ||
} | ||
return nil | ||
} |