3 Star 2 Fork 1

Gitee 极速下载 / GolangCI-Lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/golangci/golangci-lint
克隆/下载
goutils.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
Denis Isaev 提交于 2018-07-29 21:45 . Fix #126: fix working with symlinks
package goutils
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"github.com/golangci/golangci-lint/pkg/fsutils"
)
var discoverGoRootOnce sync.Once
var discoveredGoRoot string
var discoveredGoRootError error
func DiscoverGoRoot() (string, error) {
discoverGoRootOnce.Do(func() {
discoveredGoRoot, discoveredGoRootError = discoverGoRootImpl()
})
return discoveredGoRoot, discoveredGoRootError
}
func discoverGoRootImpl() (string, error) {
goroot := os.Getenv("GOROOT")
if goroot != "" {
return goroot, nil
}
output, err := exec.Command("go", "env", "GOROOT").Output()
if err != nil {
return "", fmt.Errorf("can't execute go env GOROOT: %s", err)
}
return strings.TrimSpace(string(output)), nil
}
func InGoRoot() (bool, error) {
goroot, err := DiscoverGoRoot()
if err != nil {
return false, err
}
wd, err := fsutils.Getwd()
if err != nil {
return false, err
}
// TODO: strip, then add slashes
return strings.HasPrefix(wd, goroot), nil
}
func IsCgoFilename(f string) bool {
return filepath.Base(f) == "C"
}
1
https://gitee.com/mirrors/GolangCI-Lint.git
git@gitee.com:mirrors/GolangCI-Lint.git
mirrors
GolangCI-Lint
GolangCI-Lint
v1.10.1

搜索帮助