Refactored and reorganized code

This commit is contained in:
David Allen 2024-02-23 16:06:07 -07:00
parent 86f8784c19
commit fdb0db389c
8 changed files with 384 additions and 127 deletions

View file

@ -5,6 +5,8 @@ import (
"math/rand"
"net/url"
"os"
"os/exec"
"runtime"
"strings"
)
@ -58,3 +60,22 @@ func PathExists(path string) (bool, error) {
}
return false, err
}
// https://stackoverflow.com/questions/39320371/how-start-web-server-to-open-page-in-browser-in-golang
// open opens the specified URL in the default browser of the user.
func OpenUrl(url string) error {
var cmd string
var args []string
switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}