aboutsummaryrefslogtreecommitdiff
path: root/go/ui
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui')
-rw-r--r--go/ui/openUrl.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/go/ui/openUrl.go b/go/ui/openUrl.go
new file mode 100644
index 00000000..7e227ba8
--- /dev/null
+++ b/go/ui/openUrl.go
@@ -0,0 +1,25 @@
+package ui
+
+import (
+ "os/exec"
+ "runtime"
+)
+
+// https://stackoverflow.com/questions/39320371/how-start-web-server-to-open-page-in-browser-in-golang
+// open opens the specified URL in the default browser of the user.
+func OpenUrl(url string) error {
+ var cmd string
+ var args []string
+
+ switch runtime.GOOS {
+ case "windows":
+ cmd = "cmd"
+ args = []string{"/c", "start"}
+ case "darwin":
+ cmd = "open"
+ default: // "linux", "freebsd", "openbsd", "netbsd"
+ cmd = "xdg-open"
+ }
+ args = append(args, url)
+ return exec.Command(cmd, args...).Start()
+}