hub/utils/utils.go

61 строка
1006 B
Go
Исходник Обычный вид История

2013-05-29 22:58:46 +04:00
package utils
import (
2013-05-31 04:24:06 +04:00
"errors"
2013-05-29 22:58:46 +04:00
"log"
2013-05-31 04:24:06 +04:00
"os"
"os/exec"
"runtime"
"strings"
2013-05-29 22:58:46 +04:00
)
2013-06-22 05:02:29 +04:00
func Fatal(err error) {
2013-06-22 18:41:32 +04:00
if err != nil {
log.Fatal(err)
}
2013-06-22 05:02:29 +04:00
}
2013-05-29 22:58:46 +04:00
func Check(err error) {
if err != nil {
log.Fatalf("fatal: %v", err)
}
}
2013-05-31 04:24:06 +04:00
2013-06-01 03:32:30 +04:00
func ConcatPaths(paths ...string) string {
2013-06-01 02:24:24 +04:00
return strings.Join(paths, "/")
}
2013-05-31 04:24:06 +04:00
func BrowserLauncher() ([]string, error) {
browser := os.Getenv("BROWSER")
if browser == "" {
browser = searchBrowserLauncher(runtime.GOOS)
}
if browser == "" {
return nil, errors.New("Please set $BROWSER to a web launcher")
}
return strings.Split(browser, " "), nil
}
func searchBrowserLauncher(goos string) (browser string) {
switch goos {
case "darwin":
browser = "open"
case "windows":
browser = "cmd /c start"
default:
candidates := []string{"xdg-open", "cygstart", "x-www-browser", "firefox",
"opera", "mozilla", "netscape"}
for _, b := range candidates {
path, err := exec.LookPath(b)
if err == nil {
browser = path
break
}
}
}
return browser
}