posh/pkg/util/browser/open.go
Kevin Franklin Kim 6eed6b70a8 fix: lint errors
2023-01-27 11:28:53 +01:00

34 lines
676 B
Go

package browser
import (
"context"
"fmt"
"net/url"
"os/exec"
"runtime"
)
func OpenRawURL(u string) error {
if u, err := url.Parse(u); err != nil {
return err
} else {
return OpenURL(u)
}
}
func OpenURL(u *url.URL) error {
if u == nil {
return fmt.Errorf("empty url")
}
switch runtime.GOOS {
case "linux":
return exec.CommandContext(context.TODO(), "xdg-open", u.String()).Start()
case "windows":
return exec.CommandContext(context.TODO(), "rundll32", "url.dll,FileProtocolHandler", u.String()).Start()
case "darwin":
return exec.CommandContext(context.TODO(), "open", u.String()).Start()
default:
return fmt.Errorf("unsupported platform")
}
}