}
-// getPageInfo returns the PageInfo for a package directory path. If
+// getPageInfo returns the PageInfo for a package directory dirname. If
// the parameter try is true, no errors are logged if getPageInfo fails.
// If there is no corresponding package in the directory, PageInfo.PDoc
// is nil. If there are no subdirectories, PageInfo.Dirs is nil.
//
-func (h *httpHandler) getPageInfo(relpath string, try bool) PageInfo {
- dirname := absolutePath(relpath, h.fsRoot)
-
+func (h *httpHandler) getPageInfo(dirname, relpath string, try bool) PageInfo {
// filter function to select the desired .go files
filter := func(d *os.Dir) bool {
// If we are looking at cmd documentation, only accept
// Get the best matching package: either the first one, or the
// first one whose package name matches the directory name.
- // The package name is the directory name within its parent
- // (use dirname instead of path because dirname is clean; i.e.
- // has no trailing '/').
+ // The package name is the directory name within its parent.
_, pkgname := pathutil.Split(dirname)
var pkg *ast.Package
for _, p := range pkgs {
}
relpath := r.URL.Path[len(h.pattern):]
- info := h.getPageInfo(relpath, false)
+ abspath := absolutePath(relpath, h.fsRoot)
+ info := h.getPageInfo(abspath, relpath, false)
if r.FormValue("f") == "text" {
contents := applyTemplate(packageText, "packageText", info)
packageText = packageHTML
}
- info := pkgHandler.getPageInfo(flag.Arg(0), true)
+ info := pkgHandler.getPageInfo(flag.Arg(0), flag.Arg(0), true)
if info.PDoc == nil && info.Dirs == nil {
// try again, this time assume it's a command
- info = cmdHandler.getPageInfo(flag.Arg(0), false)
+ info = cmdHandler.getPageInfo(flag.Arg(0), flag.Arg(0), false)
}
if info.PDoc != nil && flag.NArg() > 1 {