github.com/zaquestion/lab@v0.25.1/internal/browser/browse.go (about)

     1  package browser
     2  
     3  import (
     4  	"errors"
     5  	"os/exec"
     6  	"runtime"
     7  )
     8  
     9  // Open opens the specified URL in the default browser
    10  func Open(url string) error {
    11  	var cmd string
    12  	var args []string
    13  
    14  	switch runtime.GOOS {
    15  	case "darwin":
    16  		cmd = "open"
    17  	case "linux", "freebsd", "openbsd":
    18  		cmd = "xdg-open" // wherever the X server is used
    19  	case "windows":
    20  		cmd = "cmd"
    21  		args = []string{"/c", "start"}
    22  	default:
    23  		return errors.New("platform not supported")
    24  	}
    25  	args = append(args, url)
    26  	return exec.Command(cmd, args...).Start()
    27  }