github.com/april1989/origin-go-tools@v0.0.32/cmd/getgo/system.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build !plan9 6 7 package main 8 9 import ( 10 "bytes" 11 "context" 12 "os/exec" 13 "runtime" 14 "strings" 15 ) 16 17 // arch contains either amd64 or 386. 18 var arch = func() string { 19 cmd := exec.Command("uname", "-m") // "x86_64" 20 if runtime.GOOS == "windows" { 21 cmd = exec.Command("powershell", "-command", "(Get-WmiObject -Class Win32_ComputerSystem).SystemType") // "x64-based PC" 22 } 23 24 out, err := cmd.Output() 25 if err != nil { 26 // a sensible default? 27 return "amd64" 28 } 29 if bytes.Contains(out, []byte("64")) { 30 return "amd64" 31 } 32 return "386" 33 }() 34 35 func findGo(ctx context.Context, cmd string) (string, error) { 36 out, err := exec.CommandContext(ctx, cmd, "go").CombinedOutput() 37 return strings.TrimSpace(string(out)), err 38 }