detectModule reads go.mod to find the module name
(root string)
| 325 | |
| 326 | // detectModule reads go.mod to find the module name |
| 327 | func detectModule(root string) string { |
| 328 | modFile := filepath.Join(root, "go.mod") |
| 329 | f, err := os.Open(modFile) |
| 330 | if err != nil { |
| 331 | return "" |
| 332 | } |
| 333 | defer f.Close() |
| 334 | |
| 335 | scanner := bufio.NewScanner(f) |
| 336 | for scanner.Scan() { |
| 337 | line := strings.TrimSpace(scanner.Text()) |
| 338 | if strings.HasPrefix(line, "module ") { |
| 339 | return strings.TrimPrefix(line, "module ") |
| 340 | } |
| 341 | } |
| 342 | return "" |
| 343 | } |
| 344 | |
| 345 | // IsHub returns true if a file has 3+ importers |
| 346 | func (fg *FileGraph) IsHub(path string) bool { |