var (
verbose = flag.Bool("v", false, "verbose mode")
- // "fixed" file system roots
- goroot string
- cmdroot string
- pkgroot string
- tmplroot string
-
- // additional file system roots to consider
- path = flag.String("path", "", "additional package directories (colon-separated)")
+ // file system roots
+ goroot string
+ path = flag.String("path", "", "additional package directories (colon-separated)")
// layout control
tabwidth = flag.Int("tabwidth", 4, "tab width")
goroot = pathutil.Join(os.Getenv("HOME"), "go")
}
flag.StringVar(&goroot, "goroot", goroot, "Go root directory")
-
- // other flags/variables that depend on goroot
- flag.StringVar(&cmdroot, "cmdroot", pathutil.Join(goroot, "src/cmd"), "command source directory")
- flag.StringVar(&pkgroot, "pkgroot", pathutil.Join(goroot, "src/pkg"), "package source directory")
- flag.StringVar(&tmplroot, "tmplroot", pathutil.Join(goroot, "lib/godoc"), "template directory")
}
func initHandlers() {
fsMap.Init(*path)
fileServer = http.FileServer(goroot, "")
- cmdHandler = httpHandler{"/cmd/", cmdroot, false}
- pkgHandler = httpHandler{"/pkg/", pkgroot, true}
+ cmdHandler = httpHandler{"/cmd/", pathutil.Join(goroot, "src/cmd"), false}
+ pkgHandler = httpHandler{"/pkg/", pathutil.Join(goroot, "src/pkg"), true}
}
func readTemplate(name string) *template.Template {
- path := pathutil.Join(tmplroot, name)
+ path := pathutil.Join(goroot, "lib/godoc/"+name)
data, err := ioutil.ReadFile(path)
if err != nil {
log.Exitf("ReadFile %s: %v", path, err)
)
func readTemplates() {
- // have to delay until after flags processing, so that tmplroot is known
+ // have to delay until after flags processing since paths depend on goroot
dirlistHTML = readTemplate("dirlist.html")
errorHTML = readTemplate("error.html")
godocHTML = readTemplate("godoc.html")
PkgRoots []string
Timestamp uint64 // int64 to be compatible with os.Dir.Mtime_ns
Query string
+ Menu []byte
Content []byte
}
PkgRoots: fsMap.PrefixList(),
Timestamp: uint64(ts) * 1e9, // timestamp in ns
Query: query,
+ Menu: nil,
Content: content,
}
}
-func serveError(c *http.Conn, r *http.Request, relpath string, err os.Error) {
- contents := applyTemplate(errorHTML, "errorHTML", err)
- servePage(c, "File "+relpath, "", contents)
-}
-
-
func serveHTMLDoc(c *http.Conn, r *http.Request, abspath, relpath string) {
// get HTML body contents
src, err := ioutil.ReadFile(abspath)
dir, err := os.Lstat(abspath)
if err != nil {
log.Stderr(err)
- serveError(c, r, abspath, err)
+ serveError(c, r, relpath, err)
return
}
log.Stderrf("parser.parseDir: %s", err)
}
if len(pkgs) != 1 && !try {
- // TODO: should handle multiple packages
- log.Stderrf("parser.parseDir: found %d packages", len(pkgs))
+ // TODO: should handle multiple packages,
+ // error reporting disabled for now
+ // log.Stderrf("parser.parseDir: found %d packages", len(pkgs))
}
// Get the best matching package: either the first one, or the
// get directory information
var dir *Directory
- if tree, _ := fsTree.get(); tree != nil {
+ if tree, _ := fsTree.get(); tree != nil && tree.(*Directory) != nil {
// directory tree is present; lookup respective directory
// (may still fail if the file system was updated and the
// new directory tree has not yet been computed)
)
+func serveError(c *http.Conn, r *http.Request, relpath string, err os.Error) {
+ contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path!
+ servePage(c, "File "+relpath, "", contents)
+}
+
+
func exec(c *http.Conn, args []string) (status int) {
r, w, err := os.Pipe()
if err != nil {
log.Stderrf("Go Documentation Server\n")
log.Stderrf("address = %s\n", *httpaddr)
log.Stderrf("goroot = %s\n", goroot)
- log.Stderrf("cmdroot = %s\n", cmdroot)
- log.Stderrf("pkgroot = %s\n", pkgroot)
- log.Stderrf("tmplroot = %s\n", tmplroot)
log.Stderrf("tabwidth = %d\n", *tabwidth)
if !fsMap.IsEmpty() {
log.Stderr("user-defined mapping:")