MCPcopy
hub / github.com/perkeep/perkeep / GoModPackagePath

Function GoModPackagePath

internal/osutil/paths.go:404–425  ·  view source on GitHub ↗

GoModPackagePath return the absolute path for the go.mod file without "go.mod" suffix.

()

Source from the content-addressed store, hash-verified

402
403// GoModPackagePath return the absolute path for the go.mod file without "go.mod" suffix.
404func GoModPackagePath() (string, error) {
405 gmp := os.Getenv("GOMOD")
406 if gmp == "" {
407 cmd := exec.Command("go", "env", "GOMOD")
408 out, err := cmd.Output()
409 if err != nil {
410 return "", fmt.Errorf("could not run 'go env GOMOD': %v, %s", err, out)
411 }
412 gmp = strings.TrimSuffix(strings.TrimSpace(string(out)), "go.mod")
413 if gmp == "" {
414 return "", os.ErrNotExist
415 }
416 }
417 fi, err := os.Stat(gmp)
418 if err != nil {
419 return "", err
420 }
421 if !fi.IsDir() {
422 return "", fmt.Errorf("%s is not a directory: %w", gmp, os.ErrNotExist)
423 }
424 return gmp, nil
425}
426
427func failInTests() {
428 if buildinfo.TestingLinked() {

Callers 1

PkSourceRootFunction · 0.85

Calls 3

CommandMethod · 0.65
StatMethod · 0.65
IsDirMethod · 0.65

Tested by

no test coverage detected