summaryrefslogtreecommitdiff
path: root/open.go
diff options
context:
space:
mode:
authorHorus32015-12-04 17:05:00 +0100
committerHorus32015-12-04 17:05:00 +0100
commite34ee8e9ff1ebda0ec6f32e2bf93a8fd3e2a003b (patch)
treeb880e38df8524b22b98ba5cdfd4e0ced797e9bf5 /open.go
parent1276eba6a546b61b8396e838e3043f2e609ce7d4 (diff)
downloaduhttpd-e34ee8e9ff1ebda0ec6f32e2bf93a8fd3e2a003b.tar.gz
Starts a browser window on startup.
Diffstat (limited to 'open.go')
-rw-r--r--open.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/open.go b/open.go
new file mode 100644
index 0000000..93be28b
--- /dev/null
+++ b/open.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "log"
+ "os/exec"
+ "runtime"
+)
+
+// Open opens a file (or a directory or url), just as if the user had double-clicked the file's icon.
+// It uses the default application, as determined by the OS.
+func openInBrowser(path string) {
+ var args []string
+ switch runtime.GOOS {
+ case "darwin":
+ args = []string{"open", path}
+ case "windows":
+ args = []string{"cmd", "/c", "start", path}
+ default:
+ args = []string{"xdg-open", path}
+ }
+ cmd := exec.Command(args[0], args[1:]...)
+ err := cmd.Run()
+ if err != nil {
+ log.Println("u4.Open:", err)
+ }
+}