}
+func (info *PageInfo) IsEmpty() bool {
+ return info.Err != nil || info.PAst == nil && info.PDoc == nil && info.Dirs == nil
+}
+
+
type httpHandler struct {
pattern string // url pattern; e.g. "/pkg/"
fsRoot string // file system root to which the pattern is mapped
return
}
+
func main() {
flag.Usage = usage
flag.Parse()
// if there are multiple packages in a directory.
info := pkgHandler.getPageInfo(abspath, relpath, "", mode)
- if info.Err != nil || info.PAst == nil && info.PDoc == nil && info.Dirs == nil {
+ if info.IsEmpty() {
// try again, this time assume it's a command
if !pathutil.IsAbs(path) {
abspath = absolutePath(path, cmdHandler.fsRoot)
}
- info = cmdHandler.getPageInfo(abspath, relpath, "", mode)
+ cmdInfo := cmdHandler.getPageInfo(abspath, relpath, "", mode)
+ // only use the cmdInfo if it actually contains a result
+ // (don't hide errors reported from looking up a package)
+ if !cmdInfo.IsEmpty() {
+ info = cmdInfo
+ }
}
if info.Err != nil {
log.Fatalf("%v", info.Err)