browser.go 374 B

1234567891011121314151617181920212223
  1. package browser
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "runtime"
  6. )
  7. var commands = map[string]string{
  8. "windows": "start",
  9. "darwin": "open",
  10. "linux": "xdg-open",
  11. }
  12. func Open(uri string) error {
  13. run, ok := commands[runtime.GOOS]
  14. if !ok {
  15. return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
  16. }
  17. cmd := exec.Command(run, uri)
  18. return cmd.Start()
  19. }