MCPcopy Create free account
hub / github.com/marwan-at-work/mod / GetModFile

Function GetModFile

mod.go:13–23  ·  view source on GitHub ↗

GetModFile returns an AST of the given directory's go.mod file and returns err if file is not found.

(dir string)

Source from the content-addressed store, hash-verified

11// GetModFile returns an AST of the given directory's go.mod file
12// and returns err if file is not found.
13func GetModFile(dir string) (*modfile.File, error) {
14 bts, err := os.ReadFile(filepath.Join(dir, "go.mod"))
15 if err != nil {
16 return nil, fmt.Errorf("could not open go.mod file: %w", err)
17 }
18 f, err := modfile.Parse(filepath.Join(dir, "go.mod"), bts, nil)
19 if err != nil {
20 return nil, fmt.Errorf("could not parse go.mod file: %w", err)
21 }
22 return f, nil
23}

Callers 4

RunFunction · 0.92
RunFunction · 0.92
TestGetModFileFunction · 0.85
TestGetModFileErrorsFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestGetModFileFunction · 0.68
TestGetModFileErrorsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…