/ internal / utilities / browser.go
browser.go
 1  package utilities
 2  
 3  import (
 4  	"fmt"
 5  	"os/exec"
 6  	"strings"
 7  )
 8  
 9  func OpenLink(browser, url string) error {
10  	if browser == "" {
11  		return UnspecifiedBrowserError{}
12  	}
13  
14  	cmd := strings.Split(browser, " ")
15  	cmd = append(cmd, url)
16  
17  	command := exec.Command(cmd[0], cmd[1:]...) // #nosec G204 -- External command call defined in user's configuration file.
18  
19  	if err := command.Start(); err != nil {
20  		return fmt.Errorf("received an error after starting the program to view the link: %w", err)
21  	}
22  
23  	return nil
24  }