MCPcopy Index your code
hub / github.com/gopherjs/gopherjs / serveSourceTree

Method serveSourceTree

tool.go:778–794  ·  view source on GitHub ↗
(xctx gbuild.XContext, reqPath string)

Source from the content-addressed store, hash-verified

776}
777
778func (fs serveCommandFileSystem) serveSourceTree(xctx gbuild.XContext, reqPath string) (http.File, error) {
779 parts := strings.Split(path.Clean(reqPath), "/")
780 // Under Go Modules different packages can be located in different module
781 // directories, which no longer align with import paths.
782 //
783 // We don't know which part of the requested path is package import path and
784 // which is a path under the package directory, so we try different split
785 // points until the package is found successfully.
786 for i := len(parts); i > 0; i-- {
787 pkgPath := path.Clean(path.Join(parts[:i]...))
788 filePath := path.Clean(path.Join(parts[i:]...))
789 if pkg, err := xctx.Import(pkgPath, ".", build.FindOnly); err == nil {
790 return http.Dir(pkg.Dir).Open(filePath)
791 }
792 }
793 return nil, os.ErrNotExist
794}
795
796type fakeFile struct {
797 name string

Callers 1

OpenMethod · 0.95

Calls 2

OpenMethod · 0.80
ImportMethod · 0.45

Tested by

no test coverage detected