GoModPackagePath return the absolute path for the go.mod file without "go.mod" suffix.
()
| 402 | |
| 403 | // GoModPackagePath return the absolute path for the go.mod file without "go.mod" suffix. |
| 404 | func 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 | |
| 427 | func failInTests() { |
| 428 | if buildinfo.TestingLinked() { |
no test coverage detected