browser.go 437 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os/exec"
  6. "runtime"
  7. )
  8. func openURI(url string) {
  9. var err error
  10. switch runtime.GOOS {
  11. case "linux":
  12. err = exec.Command("xdg-open", url).Start()
  13. case "windows":
  14. err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
  15. case "darwin":
  16. err = exec.Command("open", url).Start()
  17. default:
  18. err = fmt.Errorf("unsupported platform")
  19. }
  20. if err != nil {
  21. log.Fatal(err)
  22. }
  23. }