2013-07-16 22:02:35 -06:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build appengine
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
// This file replaces main.go when running godoc under app-engine.
|
|
|
|
// See README.godoc-app for details.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/zip"
|
|
|
|
"log"
|
|
|
|
"path"
|
2014-12-23 16:02:05 -07:00
|
|
|
"regexp"
|
2013-07-16 22:02:35 -06:00
|
|
|
|
2014-11-09 14:50:40 -07:00
|
|
|
"golang.org/x/tools/godoc"
|
|
|
|
"golang.org/x/tools/godoc/static"
|
|
|
|
"golang.org/x/tools/godoc/vfs"
|
|
|
|
"golang.org/x/tools/godoc/vfs/mapfs"
|
|
|
|
"golang.org/x/tools/godoc/vfs/zipfs"
|
2013-07-29 22:23:23 -06:00
|
|
|
)
|
2013-07-16 22:02:35 -06:00
|
|
|
|
|
|
|
func init() {
|
2013-10-02 22:29:16 -06:00
|
|
|
playEnabled = true
|
|
|
|
|
2013-07-16 22:02:35 -06:00
|
|
|
log.Println("initializing godoc ...")
|
|
|
|
log.Printf(".zip file = %s", zipFilename)
|
|
|
|
log.Printf(".zip GOROOT = %s", zipGoroot)
|
|
|
|
log.Printf("index files = %s", indexFilenames)
|
|
|
|
|
2013-07-29 22:23:23 -06:00
|
|
|
goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
|
2013-07-16 22:02:35 -06:00
|
|
|
|
|
|
|
// read .zip file and set up file systems
|
|
|
|
const zipfile = zipFilename
|
|
|
|
rc, err := zip.OpenReader(zipfile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("%s: %s\n", zipfile, err)
|
|
|
|
}
|
|
|
|
// rc is never closed (app running forever)
|
2013-07-29 22:23:23 -06:00
|
|
|
fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
|
2013-10-02 22:29:16 -06:00
|
|
|
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
|
2013-07-16 22:02:35 -06:00
|
|
|
|
2013-07-29 22:23:23 -06:00
|
|
|
corpus := godoc.NewCorpus(fs)
|
|
|
|
corpus.Verbose = false
|
2014-06-12 23:20:15 -06:00
|
|
|
corpus.MaxResults = 10000 // matches flag default in main.go
|
2013-07-29 22:23:23 -06:00
|
|
|
corpus.IndexEnabled = true
|
|
|
|
corpus.IndexFiles = indexFilenames
|
|
|
|
if err := corpus.Init(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-03-10 05:29:27 -06:00
|
|
|
corpus.IndexDirectory = indexDirectoryDefault
|
2013-08-01 01:43:31 -06:00
|
|
|
go corpus.RunIndexer()
|
2013-07-16 22:02:35 -06:00
|
|
|
|
2013-07-29 22:23:23 -06:00
|
|
|
pres = godoc.NewPresentation(corpus)
|
|
|
|
pres.TabWidth = 8
|
|
|
|
pres.ShowPlayground = true
|
|
|
|
pres.ShowExamples = true
|
|
|
|
pres.DeclLinks = true
|
2014-12-23 16:02:05 -07:00
|
|
|
pres.NotesRx = regexp.MustCompile("BUG")
|
2013-07-16 22:02:35 -06:00
|
|
|
|
2013-08-19 23:29:56 -06:00
|
|
|
readTemplates(pres, true)
|
2013-07-29 22:23:23 -06:00
|
|
|
registerHandlers(pres)
|
2013-07-16 22:02:35 -06:00
|
|
|
|
|
|
|
log.Println("godoc initialization complete")
|
|
|
|
}
|