Skip to content

Instantly share code, notes, and snippets.

@theGeekPirate
Last active December 5, 2019 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theGeekPirate/743c84e7347124a64a97 to your computer and use it in GitHub Desktop.
Save theGeekPirate/743c84e7347124a64a97 to your computer and use it in GitHub Desktop.
Opens the browser on all non-mobile supported platforms
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