29 lines
585 B
Go
29 lines
585 B
Go
package platform
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"runtime"
|
|
)
|
|
|
|
func OpenURL(url string) error {
|
|
name, args, err := openCommand(runtime.GOOS, url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return exec.Command(name, args...).Start()
|
|
}
|
|
|
|
func openCommand(goos, url string) (string, []string, error) {
|
|
switch goos {
|
|
case "darwin":
|
|
return "open", []string{url}, nil
|
|
case "linux":
|
|
return "xdg-open", []string{url}, nil
|
|
case "windows":
|
|
return "rundll32", []string{"url.dll,FileProtocolHandler", url}, nil
|
|
default:
|
|
return "", nil, fmt.Errorf("opening URLs is not supported on %s", goos)
|
|
}
|
|
}
|