2022-04-26 10:24:16 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
2022-05-10 10:51:04 +03:00
|
|
|
"strings"
|
2022-04-26 10:24:16 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func OpenBrowser(url string) {
|
|
|
|
var err error
|
|
|
|
|
2022-05-10 10:51:04 +03:00
|
|
|
fmt.Println()
|
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
err = exec.Command("xdg-open", url).Start()
|
|
|
|
case "windows":
|
|
|
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
|
|
|
case "darwin":
|
|
|
|
err = exec.Command("open", url).Start()
|
|
|
|
default:
|
|
|
|
err = fmt.Errorf("unsupported platform")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
2022-05-10 10:51:04 +03:00
|
|
|
s := "If your web browser doesn't open automatically, navigate to " + url + " manually"
|
|
|
|
t := strings.Repeat("=", len(s))
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println(t)
|
|
|
|
fmt.Println(s)
|
|
|
|
fmt.Println(t)
|
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
}
|