This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
appinit.go
87 lines (72 loc) · 2.23 KB
/
appinit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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 (
"go/doc"
"log"
"regexp"
"golang.org/x/tools/godoc/vfs"
"github.com/golang-china/golangdoc/godoc"
"github.com/golang-china/golangdoc/local"
)
func init() {
playEnabled = true
log.Println("initializing godoc ...")
log.Printf(".zip file = %s", flagZipFilename)
log.Printf(".zip GOROOT = %s", flagZipGoroot)
log.Printf("index files = %s", flagIndexFilenames)
// Determine file system to use.
local.Init(flagZipGoroot, local.Default, flagZipFilename, "", "")
fs.Bind("/", local.RootFS(), "/", vfs.BindReplace)
fs.Bind("/lib/godoc", local.StaticFS(*flagLang), "/", vfs.BindReplace)
fs.Bind("/doc", local.DocumentFS(*flagLang), "/", vfs.BindReplace)
corpus := godoc.NewCorpus(fs)
corpus.Verbose = false
corpus.MaxResults = 10000 // matches flag default in main.go
corpus.IndexEnabled = true
corpus.IndexFiles = flagIndexFilenames
// translate hook
corpus.SummarizePackage = func(importPath string, langs ...string) (summary string, showList, ok bool) {
lang := *flagLang
if len(langs) > 0 && langs[0] != "" {
lang = langs[0]
}
if lang == "en" || lang == "raw" || lang == "EN" {
lang = ""
}
if pkg := local.Package(lang, importPath); pkg != nil {
summary = doc.Synopsis(pkg.Doc)
}
ok = (summary != "")
return
}
corpus.TranslateDocPackage = func(pkg *doc.Package, langs ...string) *doc.Package {
lang := *flagLang
if len(langs) > 0 && langs[0] != "" {
lang = langs[0]
}
if lang == "en" || lang == "raw" || lang == "EN" {
lang = ""
}
return local.Package(lang, pkg.ImportPath, pkg)
}
if err := corpus.Init(); err != nil {
log.Fatal(err)
}
if corpus.IndexEnabled && corpus.IndexFiles != "" {
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)
registerHandlers(pres)
log.Println("godoc initialization complete")
}