code: func PackagePath(path string) (string, error) {
  	absPath, err := filepath.Abs(path)
  	if err != nil {
  		absPath = path
  	}
  	gopaths := filepath.SplitList(envOr("GOPATH", build.Default.GOPATH))
  	if os.Getenv("GO111MODULE") != "on" { // GOPATH mode
  		for _, gopath := range gopaths {
  			if gp, err := filepath.Abs(gopath); err == nil {
  				gopath = gp
  			}
  			if filepath.HasPrefix(absPath, gopath) {
  				base := filepath.FromSlash(gopath + "/src")
  				rel, err := filepath.Rel(base, absPath)
  				return filepath.ToSlash(rel), err
  			}
  		}
  	}
  	if os.Getenv("GO111MODULE") != "off" { // Module mode
  		root, file := findModuleRoot(absPath, "", false)
  		if root != "" {
  			content, err := ioutil.ReadFile(filepath.Join(root, file))
  			if err == nil {
  				p := modulePath(content)
  				base := filepath.FromSlash(root)
  				rel, err := filepath.Rel(base, absPath)
  				return filepath.ToSlash(filepath.Join(p, rel)), err
  			}
  		}
  	}
  	return "", fmt.Errorf("%s does not contain a Go package", absPath)
  }
docs: // PackagePath returns the Go package path for the directory that lives under the given absolute
  // file path.