GoPLS Viewer

Home|gopls/cmd/getgo/system.go
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//go:build !plan9
6// +build !plan9
7
8package main
9
10import (
11    "bytes"
12    "context"
13    exec "golang.org/x/sys/execabs"
14    "runtime"
15    "strings"
16)
17
18// arch contains either amd64 or 386.
19var arch = func() string {
20    cmd := exec.Command("uname""-m"// "x86_64"
21    if runtime.GOOS == "windows" {
22        cmd = exec.Command("powershell""-command""(Get-WmiObject -Class Win32_ComputerSystem).SystemType"// "x64-based PC"
23    }
24
25    outerr := cmd.Output()
26    if err != nil {
27        // a sensible default?
28        return "amd64"
29    }
30    if bytes.Contains(out, []byte("64")) {
31        return "amd64"
32    }
33    return "386"
34}()
35
36func findGo(ctx context.Contextcmd string) (stringerror) {
37    outerr := exec.CommandContext(ctxcmd"go").CombinedOutput()
38    return strings.TrimSpace(string(out)), err
39}
40
MembersX
findGo.cmd
findGo.out
findGo.err
cmd
out
err
findGo
findGo.ctx
Members
X