我怎么能 100% 确定并检查我的应用程序的 Go 执行,1、2 给我真还是假
1) 操作系统 Windows XP, Vista, 7, 8, 32/64-bit OK 如果那台电脑已经安装了 Google Chrome 浏览器?
2) 操作系统 Mac/Apple,是否有 Google Chrome 浏览器?
package main
import "os/exec"
import "runtime"
import "fmt"
import "net/http"
const url = "http://localhsot:9090"
func main() {
myos := runtime.GOOS // linux, freebsd, netbsd, openbsd, plan9, darwin, windows
fmt.Println (runtime.GOARCH) // 386, amd64, arm
if myos == "windows" {
if myarch == "386" {
chrome := "C:/Program Files/Google/Chrome/Application/chrome.exe"
} else {
chrome := "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
}
cmd := exec.Command(chrome, "--chrome-frame", url)
err := cmd.Start()
if err != nil {
println("Failed to start chrome:", err)
}
} else if myos == "darwin" {
if myarch == "386" {
cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
} else {
cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
}
err := cmd.Start()
if err != nil {
fmt.Println("failed")
}
} else {
if myarch == "386" {
chrome := "google-chrome"
} else {
chrome := "google-chrome"
}
cmd := exec.Command(chrome, "--chrome-frame", url)
err := cmd.Start()
if err != nil {
fmt.Println("failed")
}
}
}
潇湘沐
相关分类