MCPcopy Create free account
hub / github.com/egonelbre/exp / ParseModule

Function ParseModule

coverage_example/parse/main.go:19–43  ·  view source on GitHub ↗

See https://go.dev/ref/mod#go-mod-file for the spec.

(path string)

Source from the content-addressed store, hash-verified

17
18// See https://go.dev/ref/mod#go-mod-file for the spec.
19func ParseModule(path string) (Module, error) {
20 data, err := os.ReadFile(path)
21 if err != nil {
22 return Module{}, err
23 }
24
25 for _, line := range strings.Split(string(data), "\n") {
26 line = strings.TrimSpace(line)
27 // is it a module defintion line?
28 if strings.HasPrefix(line, "module ") {
29 // trim the prefix
30 modulename := strings.TrimPrefix(line, "module ")
31 // cut any trailing comments, if there are any
32 modulename, _, _ = strings.Cut(modulename, "//")
33 modulename = strings.TrimSpace(modulename)
34
35 return Module{
36 Prefix: modulename + "/",
37 Dir: filepath.Dir(path),
38 }, nil
39 }
40 }
41
42 return Module{}, errors.New("invalid module")
43}
44
45func TranslatePath(pkgpath string, modules []Module) (path string, found bool) {
46 for _, module := range modules {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected