123456789101112131415161718192021222324252627282930313233343536373839 |
- package util
- import (
- "fmt"
- "os/exec"
- "runtime"
- )
- func OpenBrowser(url string) error {
- var err error
- 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")
- }
- return err
- }
- // checkAvailablePort 端口可用检测,netstat 只适合linux
- func checkAvailablePort(port int) (res bool) {
- checkStatement := fmt.Sprintf(`lsof -i:%d -t`, port)
- output, err := exec.Command("sh", "-c", checkStatement).Output()
- if err != nil {
- return false
- }
- if len(output) > 0 {
- return false
- }
- return true
- }
|