示例#1
0
func registerHandlers(pres *godoc.Presentation) {
	if pres == nil {
		panic("nil Presentation")
	}
	http.HandleFunc("/doc/codewalk/", codewalk)
	http.Handle("/doc/play/", pres.FileServer())
	http.Handle("/robots.txt", pres.FileServer())
	http.Handle("/", pres)
	http.Handle("/pkg/C/", redirect.Handler("/cmd/cgo/"))
	redirect.Register(nil)
}
示例#2
0
func registerHandlers() {
	corpus = godoc.NewCorpus(fs)
	corpus.MaxResults = 100
	if err := corpus.Init(); err != nil {
		panic(err)
	}

	/*
		// TODO: enable indexing and analysis.
		// Currently indexing consumes a lot of memory that mobile devices cannot tolerate.
		// Static analysis does not handle the current unusual GOROOT setup.
		corpus.IndexEnabled = true
		corpus.IndexDirectory = func(dir string) bool {
			return dir != "/pkg" && !strings.HasPrefix(dir, "/pkg/")
		}
		corpus.IndexInterval = -1
		go corpus.RunIndexer()
		go analysis.Run(true, &corpus.Analysis)
	*/

	// presentation
	pres = godoc.NewPresentation(corpus)
	pres.TabWidth = tabWidth
	pres.ShowTimestamps = false
	pres.ShowExamples = true
	pres.DeclLinks = true
	pres.HTMLMode = true
	pres.PackageText = readTemplate("package.txt")
	pres.SearchText = readTemplate("search.txt")
	pres.CallGraphHTML = readTemplate("callgraph.html")
	pres.DirlistHTML = readTemplate("dirlist.html")
	pres.ErrorHTML = readTemplate("error.html")
	pres.ExampleHTML = readTemplate("example.html")
	pres.GodocHTML = readTemplate("godoc.html")
	pres.ImplementsHTML = readTemplate("implements.html")
	pres.MethodSetHTML = readTemplate("methodset.html")
	pres.PackageHTML = readTemplate("package.html")
	pres.SearchHTML = readTemplate("search.html")
	pres.SearchDocHTML = readTemplate("searchdoc.html")
	pres.SearchCodeHTML = readTemplate("searchcode.html")
	pres.SearchTxtHTML = readTemplate("searchtxt.html")
	pres.SearchDescXML = readTemplate("opensearch.xml")

	// handlers
	http.Handle("/doc/play/", pres.FileServer())
	http.Handle("/robots.txt", pres.FileServer()) // do we care?
	http.Handle("/", pres)
	http.Handle("/pkg/C/", redirect.Handler("/cmd/cgo/"))

	redirect.Register(nil)
}
示例#3
0
文件: handlers.go 项目: jehiah/tools
func registerHandlers(pres *godoc.Presentation) *http.ServeMux {
	if pres == nil {
		panic("nil Presentation")
	}
	mux := http.NewServeMux()
	mux.HandleFunc("/doc/codewalk/", codewalk)
	mux.Handle("/doc/play/", pres.FileServer())
	mux.Handle("/robots.txt", pres.FileServer())
	mux.Handle("/", pres)
	mux.Handle("/pkg/C/", redirect.Handler("/cmd/cgo/"))
	redirect.Register(mux)
	http.Handle("/", hostEnforcerHandler{mux})

	return mux
}