GoPLS Viewer

Home|gopls/cmd/godoc/goroot.go
1// Copyright 2018 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
5package main
6
7import (
8    exec "golang.org/x/sys/execabs"
9    "os"
10    "path/filepath"
11    "runtime"
12    "strings"
13)
14
15func findGOROOT() string {
16    if env := os.Getenv("GOROOT"); env != "" {
17        return filepath.Clean(env)
18    }
19    def := filepath.Clean(runtime.GOROOT())
20    if runtime.Compiler == "gccgo" {
21        // gccgo has no real GOROOT, and it certainly doesn't
22        // depend on the executable's location.
23        return def
24    }
25    outerr := exec.Command("go""env""GOROOT").Output()
26    if err != nil {
27        return def
28    }
29    return strings.TrimSpace(string(out))
30}
31
MembersX
findGOROOT
findGOROOT.env
findGOROOT.def
findGOROOT.out
findGOROOT.err
filepath
Members
X