mirror of
https://github.com/golang/go.git
synced 2025-05-07 00:23:03 +00:00
These were built inside Google but have been in production for years. Move them into the public tools repository so that they can be more easily maintained. This is step one to moving the entire golang.org deployment process out of Google's internal source repository. Change-Id: I72f875c5020b3f58f1c0cea1d19268e0f991833f Reviewed-on: https://go-review.googlesource.com/14842 Reviewed-by: Chris Broadfoot <cbro@golang.org>
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
// 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"
|
|
"regexp"
|
|
|
|
"golang.org/x/tools/godoc"
|
|
"golang.org/x/tools/godoc/dl"
|
|
"golang.org/x/tools/godoc/proxy"
|
|
"golang.org/x/tools/godoc/short"
|
|
"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"
|
|
|
|
"google.golang.org/appengine"
|
|
)
|
|
|
|
func init() {
|
|
enforceHosts = !appengine.IsDevAppServer()
|
|
playEnabled = true
|
|
|
|
log.Println("initializing godoc ...")
|
|
log.Printf(".zip file = %s", zipFilename)
|
|
log.Printf(".zip GOROOT = %s", zipGoroot)
|
|
log.Printf("index files = %s", indexFilenames)
|
|
|
|
goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
|
|
|
|
// 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)
|
|
fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
|
|
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
|
|
|
|
corpus := godoc.NewCorpus(fs)
|
|
corpus.Verbose = false
|
|
corpus.MaxResults = 10000 // matches flag default in main.go
|
|
corpus.IndexEnabled = true
|
|
corpus.IndexFiles = indexFilenames
|
|
if err := corpus.Init(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
corpus.IndexDirectory = indexDirectoryDefault
|
|
go corpus.RunIndexer()
|
|
|
|
pres = godoc.NewPresentation(corpus)
|
|
pres.TabWidth = 8
|
|
pres.ShowPlayground = true
|
|
pres.ShowExamples = true
|
|
pres.DeclLinks = true
|
|
pres.NotesRx = regexp.MustCompile("BUG")
|
|
|
|
readTemplates(pres, true)
|
|
mux := registerHandlers(pres)
|
|
dl.RegisterHandlers(mux)
|
|
proxy.RegisterHandlers(mux)
|
|
short.RegisterHandlers(mux)
|
|
|
|
log.Println("godoc initialization complete")
|
|
}
|