func listModuleDir()

in dev-tools/mage/gotool/go.go [133:151]


func listModuleDir(pkg string, vendor bool) (string, error) {
	env := map[string]string{
		// Make sure GOFLAGS does not influence behaviour.
		"GOFLAGS": "",
	}
	args := []string{"-m", "-f", "{{.Dir}}"}
	if vendor {
		args = append(args, "-mod=vendor")
	}
	args = append(args, pkg)
	lines, err := getLines(callGo(env, "list", args...))
	if err != nil {
		return "", err
	}
	if n := len(lines); n != 1 {
		return "", fmt.Errorf("expected 1 line, got %d while looking for %s", n, pkg)
	}
	return lines[0], nil
}