summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/appinit.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/godoc/appinit.go')
-rw-r--r--src/cmd/godoc/appinit.go74
1 files changed, 26 insertions, 48 deletions
diff --git a/src/cmd/godoc/appinit.go b/src/cmd/godoc/appinit.go
index 9b8987223..70da00110 100644
--- a/src/cmd/godoc/appinit.go
+++ b/src/cmd/godoc/appinit.go
@@ -2,58 +2,38 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// To run godoc under app engine, substitute main.go with
-// this file (appinit.go), provide a .zip file containing
-// the file system to serve, and adjust the configuration
-// parameters in appconfig.go accordingly.
-//
-// The current app engine SDK may be based on an older Go
-// release version. To correct for version skew, copy newer
-// packages into the alt directory (e.g. alt/strings) and
-// adjust the imports in the godoc source files (e.g. from
-// `import "strings"` to `import "alt/strings"`). Both old
-// and new packages may be used simultaneously as long as
-// there is no package global state that needs to be shared.
-//
-// The directory structure should look as follows:
-//
-// godoc // directory containing the app engine app
-// alt // alternative packages directory to
-// // correct for version skew
-// strings // never version of the strings package
-// ... //
-// app.yaml // app engine control file
-// go.zip // zip file containing the file system to serve
-// godoc // contains godoc sources
-// appinit.go // this file instead of godoc/main.go
-// appconfig.go // godoc for app engine configuration
-// ... //
-//
-// To run app the engine emulator locally:
-//
-// dev_appserver.py -a 0 godoc
-//
-// godoc is the top-level "goroot" directory.
-// The godoc home page is served at: <hostname>:8080 and localhost:8080.
+// +build appengine
package main
+// This file replaces main.go when running godoc under app-engine.
+// See README.godoc-app for details.
+
import (
- "alt/archive/zip"
- "http"
+ "archive/zip"
"log"
- "os"
+ "net/http"
+ "path"
)
-func serveError(w http.ResponseWriter, r *http.Request, relpath string, err os.Error) {
+func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path!
w.WriteHeader(http.StatusNotFound)
- servePage(w, "File "+relpath, "", "", contents)
+ servePage(w, relpath, "File "+relpath, "", "", contents)
}
func init() {
log.Println("initializing godoc ...")
+ log.Printf(".zip file = %s", zipFilename)
+ log.Printf(".zip GOROOT = %s", zipGoroot)
+ log.Printf("index files = %s", indexFilenames)
+
+ // initialize flags for app engine
*goroot = path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
+ *indexEnabled = true
+ *indexFiles = indexFilenames
+ *maxResults = 100 // reduce latency by limiting the number of fulltext search results
+ *indexThrottle = 0.3 // in case *indexFiles is empty (and thus the indexer is run)
// read .zip file and set up file systems
const zipfile = zipFilename
@@ -61,26 +41,24 @@ func init() {
if err != nil {
log.Fatalf("%s: %s\n", zipfile, err)
}
- fs = NewZipFS(rc)
- fsHttp = NewHttpZipFS(rc, *goroot)
+ // rc is never closed (app running forever)
+ fs.Bind("/", NewZipFS(rc, zipFilename), *goroot, bindReplace)
// initialize http handlers
- initHandlers()
readTemplates()
+ initHandlers()
registerPublicHandlers(http.DefaultServeMux)
// initialize default directory tree with corresponding timestamp.
initFSTree()
- // initialize directory trees for user-defined file systems (-path flag).
- initDirTrees()
+ // Immediately update metadata.
+ updateMetadata()
- // create search index
- // TODO(gri) Disabled for now as it takes too long. Find a solution for this.
- /*
- *indexEnabled = true
+ // initialize search index
+ if *indexEnabled {
go indexer()
- */
+ }
log.Println("godoc initialization complete")
}