Last active
December 5, 2019 04:31
-
-
Save theGeekPirate/743c84e7347124a64a97 to your computer and use it in GitHub Desktop.
Opens the browser on all non-mobile supported platforms
This file contains hidden or 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
package browser | |
import ( | |
"fmt" | |
"os/exec" | |
"runtime" | |
) | |
// TODO: aix, android, hurd, illumos, ?js?, nacl, zos | |
// TODO: Test plan9, solaris (can we just use "sdtwebclient" instead?) | |
// The GOOS list comes from https://github.com/golang/go/blob/master/src/go/build/syslist.go | |
var commands = map[string]string{ | |
"darwin": "open", | |
"dragonfly": "xdg-open", | |
"freebsd": "xdg-open", | |
"linux": "xdg-open", | |
"netbsd": "xdg-open", | |
"openbsd": "xdg-open", | |
// TODO: Does this open mothra or abaco (the two Plan 9 web browsers) by default? | |
"plan9": "web", | |
"solaris": "/usr/dt/bin/sdtwebclient", | |
"windows": "start", | |
} | |
func Open(URI string) error { | |
run, ok := commands[runtime.GOOS] | |
if !ok { | |
return fmt.Errorf(`This application is unable to open the browser on your "%s" system. Please file a bug.`, runtime.GOOS) | |
} | |
cmd := exec.Command(run, URI) | |
return cmd.Start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment