github.com/samlitowitz/goimportcycle@v1.0.9/internal/modfile/get_module_path.go (about)

     1  package modfile
     2  
     3  import (
     4  	"os"
     5  
     6  	"golang.org/x/mod/modfile"
     7  )
     8  
     9  func GetModulePath(goModFile string) (string, error) {
    10  	goMod, err := os.ReadFile(goModFile)
    11  	if err != nil {
    12  		return "", err
    13  	}
    14  	modPath := modfile.ModulePath(goMod)
    15  	if modPath == "" {
    16  		return "", &ModulePathNotFoundError{}
    17  	}
    18  	return modPath, nil
    19  }