@@ -58,50 +58,50 @@ const (
58
58
var (
59
59
// file system to serve
60
60
// (with e.g.: zip -r go.zip $GOROOT -i \*.go -i \*.html -i \*.css -i \*.js -i \*.txt -i \*.c -i \*.h -i \*.s -i \*.png -i \*.jpg -i \*.sh -i favicon.ico)
61
- zipfile = flag .String ("zip" , "" , "zip file providing the file system to serve; disabled if empty" )
61
+ flagZipfile = flag .String ("zip" , "" , "zip file providing the file system to serve; disabled if empty" )
62
62
63
63
// file-based index
64
- writeIndex = flag .Bool ("write_index" , false , "write index to a file; the file name must be specified with -index_files" )
64
+ flagWriteIndex = flag .Bool ("write_index" , false , "write index to a file; the file name must be specified with -index_files" )
65
65
66
- analysisFlag = flag .String ("analysis" , "" , `comma-separated list of analyses to perform (supported: type, pointer). See http://golang.org/lib/godoc/analysis/help.html` )
66
+ flagAnalysisFlag = flag .String ("analysis" , "" , `comma-separated list of analyses to perform (supported: type, pointer). See http://golang.org/lib/godoc/analysis/help.html` )
67
67
68
68
// network
69
- httpAddr = flag .String ("http" , "" , "HTTP service address (e.g., '" + defaultAddr + "')" )
70
- serverAddr = flag .String ("server" , "" , "webserver address for command line searches" )
69
+ flagHttpAddr = flag .String ("http" , "" , "HTTP service address (e.g., '" + defaultAddr + "')" )
70
+ flagServerAddr = flag .String ("server" , "" , "webserver address for command line searches" )
71
71
72
72
// layout control
73
- html = flag .Bool ("html" , false , "print HTML in command-line mode" )
74
- srcMode = flag .Bool ("src" , false , "print (exported) source in command-line mode" )
75
- urlFlag = flag .String ("url" , "" , "print HTML for named URL" )
73
+ flagHtml = flag .Bool ("html" , false , "print HTML in command-line mode" )
74
+ flagSrcMode = flag .Bool ("src" , false , "print (exported) source in command-line mode" )
75
+ flagUrlFlag = flag .String ("url" , "" , "print HTML for named URL" )
76
76
77
77
// command-line searches
78
- query = flag .Bool ("q" , false , "arguments are considered search queries" )
78
+ flagQuery = flag .Bool ("q" , false , "arguments are considered search queries" )
79
79
80
- verbose = flag .Bool ("v" , false , "verbose mode" )
80
+ flagVerbose = flag .Bool ("v" , false , "verbose mode" )
81
81
82
82
// file system roots
83
83
// TODO(gri) consider the invariant that goroot always end in '/'
84
- goroot = flag .String ("goroot" , runtime .GOROOT (), "Go root directory" )
84
+ flagGoroot = flag .String ("goroot" , runtime .GOROOT (), "Go root directory" )
85
85
86
86
// layout control
87
- tabWidth = flag .Int ("tabwidth" , 4 , "tab width" )
88
- showTimestamps = flag .Bool ("timestamps" , false , "show timestamps with directory listings" )
89
- templateDir = flag .String ("templates" , "" , "directory containing alternate template files" )
90
- showPlayground = flag .Bool ("play" , false , "enable playground in web interface" )
91
- showExamples = flag .Bool ("ex" , false , "show examples in command line mode" )
92
- declLinks = flag .Bool ("links" , true , "link identifiers to their declarations" )
87
+ flagTabWidth = flag .Int ("tabwidth" , 4 , "tab width" )
88
+ flagShowTimestamps = flag .Bool ("timestamps" , false , "show timestamps with directory listings" )
89
+ flagTemplateDir = flag .String ("templates" , "" , "directory containing alternate template files" )
90
+ flagShowPlayground = flag .Bool ("play" , false , "enable playground in web interface" )
91
+ flagShowExamples = flag .Bool ("ex" , false , "show examples in command line mode" )
92
+ flagDeclLinks = flag .Bool ("links" , true , "link identifiers to their declarations" )
93
93
94
94
// search index
95
- indexEnabled = flag .Bool ("index" , false , "enable search index" )
96
- indexFiles = flag .String ("index_files" , "" , "glob pattern specifying index files; if not empty, the index is read from these files in sorted order" )
97
- maxResults = flag .Int ("maxresults" , 10000 , "maximum number of full text search results shown" )
98
- indexThrottle = flag .Float64 ("index_throttle" , 0.75 , "index throttle value; 0.0 = no time allocated, 1.0 = full throttle" )
95
+ flagIndexEnabled = flag .Bool ("index" , false , "enable search index" )
96
+ flagIndexFiles = flag .String ("index_files" , "" , "glob pattern specifying index files; if not empty, the index is read from these files in sorted order" )
97
+ flagMaxResults = flag .Int ("maxresults" , 10000 , "maximum number of full text search results shown" )
98
+ flagIndexThrottle = flag .Float64 ("index_throttle" , 0.75 , "index throttle value; 0.0 = no time allocated, 1.0 = full throttle" )
99
99
100
100
// source code notes
101
- notesRx = flag .String ("notes" , "BUG" , "regular expression matching note markers to show" )
101
+ flagNotesRx = flag .String ("notes" , "BUG" , "regular expression matching note markers to show" )
102
102
103
103
// local language
104
- lang = flag .String ("lang" , "" , "local language" )
104
+ flagLang = flag .String ("lang" , "" , "local language" )
105
105
)
106
106
107
107
func usage () {
@@ -121,7 +121,7 @@ func loggingHandler(h http.Handler) http.Handler {
121
121
122
122
func handleURLFlag () {
123
123
// Try up to 10 fetches, following redirects.
124
- urlstr := * urlFlag
124
+ urlstr := * flagUrlFlag
125
125
for i := 0 ; i < 10 ; i ++ {
126
126
// Prepare request.
127
127
u , err := url .Parse (urlstr )
@@ -157,16 +157,16 @@ func handleURLFlag() {
157
157
158
158
func runGodoc () {
159
159
// Determine file system to use.
160
- local .Init (* goroot , * zipfile , * templateDir , build .Default .GOPATH )
160
+ local .Init (* flagGoroot , * flagZipfile , * flagTemplateDir , build .Default .GOPATH )
161
161
fs .Bind ("/" , local .RootFS (), "/" , vfs .BindReplace )
162
- fs .Bind ("/lib/godoc" , local .StaticFS (* lang ), "/" , vfs .BindReplace )
163
- fs .Bind ("/doc" , local .DocumentFS (* lang ), "/" , vfs .BindReplace )
162
+ fs .Bind ("/lib/godoc" , local .StaticFS (* flagLang ), "/" , vfs .BindReplace )
163
+ fs .Bind ("/doc" , local .DocumentFS (* flagLang ), "/" , vfs .BindReplace )
164
164
165
- httpMode := * httpAddr != ""
165
+ httpMode := * flagHttpAddr != ""
166
166
167
167
var typeAnalysis , pointerAnalysis bool
168
- if * analysisFlag != "" {
169
- for _ , a := range strings .Split (* analysisFlag , "," ) {
168
+ if * flagAnalysisFlag != "" {
169
+ for _ , a := range strings .Split (* flagAnalysisFlag , "," ) {
170
170
switch a {
171
171
case "type" :
172
172
typeAnalysis = true
@@ -182,62 +182,62 @@ func runGodoc() {
182
182
183
183
// translate hook
184
184
corpus .SummarizePackage = func (importPath string ) (summary string , showList , ok bool ) {
185
- if pkg := local .Package (* lang , importPath ); pkg != nil {
185
+ if pkg := local .Package (* flagLang , importPath ); pkg != nil {
186
186
summary = doc .Synopsis (pkg .Doc )
187
187
}
188
188
ok = (summary != "" )
189
189
return
190
190
}
191
191
corpus .TranslateDocPackage = func (pkg * doc.Package ) * doc.Package {
192
- return local .Package (* lang , pkg .ImportPath , pkg )
192
+ return local .Package (* flagLang , pkg .ImportPath , pkg )
193
193
}
194
194
195
- corpus .Verbose = * verbose
196
- corpus .MaxResults = * maxResults
197
- corpus .IndexEnabled = * indexEnabled && httpMode
198
- if * maxResults == 0 {
195
+ corpus .Verbose = * flagVerbose
196
+ corpus .MaxResults = * flagMaxResults
197
+ corpus .IndexEnabled = * flagIndexEnabled && httpMode
198
+ if * flagMaxResults == 0 {
199
199
corpus .IndexFullText = false
200
200
}
201
- corpus .IndexFiles = * indexFiles
202
- corpus .IndexThrottle = * indexThrottle
203
- if * writeIndex {
201
+ corpus .IndexFiles = * flagIndexFiles
202
+ corpus .IndexThrottle = * flagIndexThrottle
203
+ if * flagWriteIndex {
204
204
corpus .IndexThrottle = 1.0
205
205
corpus .IndexEnabled = true
206
206
}
207
- if * writeIndex || httpMode || * urlFlag != "" {
207
+ if * flagWriteIndex || httpMode || * flagUrlFlag != "" {
208
208
if err := corpus .Init (); err != nil {
209
209
log .Fatal (err )
210
210
}
211
211
}
212
212
213
213
pres = godoc .NewPresentation (corpus )
214
- pres .TabWidth = * tabWidth
215
- pres .ShowTimestamps = * showTimestamps
216
- pres .ShowPlayground = * showPlayground
217
- pres .ShowExamples = * showExamples
218
- pres .DeclLinks = * declLinks
219
- pres .SrcMode = * srcMode
220
- pres .HTMLMode = * html
221
- if * notesRx != "" {
222
- pres .NotesRx = regexp .MustCompile (* notesRx )
214
+ pres .TabWidth = * flagTabWidth
215
+ pres .ShowTimestamps = * flagShowTimestamps
216
+ pres .ShowPlayground = * flagShowPlayground
217
+ pres .ShowExamples = * flagShowExamples
218
+ pres .DeclLinks = * flagDeclLinks
219
+ pres .SrcMode = * flagSrcMode
220
+ pres .HTMLMode = * flagHtml
221
+ if * flagNotesRx != "" {
222
+ pres .NotesRx = regexp .MustCompile (* flagNotesRx )
223
223
}
224
224
225
- readTemplates (pres , httpMode || * urlFlag != "" )
225
+ readTemplates (pres , httpMode || * flagUrlFlag != "" )
226
226
registerHandlers (pres )
227
227
228
- if * writeIndex {
228
+ if * flagWriteIndex {
229
229
// Write search index and exit.
230
- if * indexFiles == "" {
230
+ if * flagIndexFiles == "" {
231
231
log .Fatal ("no index file specified" )
232
232
}
233
233
234
234
log .Println ("initialize file systems" )
235
- * verbose = true // want to see what happens
235
+ * flagVerbose = true // want to see what happens
236
236
237
237
corpus .UpdateIndex ()
238
238
239
- log .Println ("writing index file" , * indexFiles )
240
- f , err := os .Create (* indexFiles )
239
+ log .Println ("writing index file" , * flagIndexFiles )
240
+ f , err := os .Create (* flagIndexFiles )
241
241
if err != nil {
242
242
log .Fatal (err )
243
243
}
@@ -252,33 +252,33 @@ func runGodoc() {
252
252
}
253
253
254
254
// Print content that would be served at the URL *urlFlag.
255
- if * urlFlag != "" {
255
+ if * flagUrlFlag != "" {
256
256
handleURLFlag ()
257
257
return
258
258
}
259
259
260
260
if httpMode {
261
261
// HTTP server mode.
262
262
var handler http.Handler = http .DefaultServeMux
263
- if * verbose {
263
+ if * flagVerbose {
264
264
log .Printf ("Go Documentation Server" )
265
265
log .Printf ("version = %s" , runtime .Version ())
266
- log .Printf ("address = %s" , * httpAddr )
267
- log .Printf ("goroot = %s" , * goroot )
268
- log .Printf ("tabwidth = %d" , * tabWidth )
266
+ log .Printf ("address = %s" , * flagHttpAddr )
267
+ log .Printf ("goroot = %s" , * flagGoroot )
268
+ log .Printf ("tabwidth = %d" , * flagTabWidth )
269
269
switch {
270
- case ! * indexEnabled :
270
+ case ! * flagIndexEnabled :
271
271
log .Print ("search index disabled" )
272
- case * maxResults > 0 :
273
- log .Printf ("full text index enabled (maxresults = %d)" , * maxResults )
272
+ case * flagMaxResults > 0 :
273
+ log .Printf ("full text index enabled (maxresults = %d)" , * flagMaxResults )
274
274
default :
275
275
log .Print ("identifier search index enabled" )
276
276
}
277
277
handler = loggingHandler (handler )
278
278
}
279
279
280
280
// Initialize search index.
281
- if * indexEnabled {
281
+ if * flagIndexEnabled {
282
282
go corpus .RunIndexer ()
283
283
}
284
284
@@ -288,14 +288,14 @@ func runGodoc() {
288
288
}
289
289
290
290
// Start http server.
291
- if err := http .ListenAndServe (* httpAddr , handler ); err != nil {
292
- log .Fatalf ("ListenAndServe %s: %v" , * httpAddr , err )
291
+ if err := http .ListenAndServe (* flagHttpAddr , handler ); err != nil {
292
+ log .Fatalf ("ListenAndServe %s: %v" , * flagHttpAddr , err )
293
293
}
294
294
295
295
return
296
296
}
297
297
298
- if * query {
298
+ if * flagQuery {
299
299
handleRemoteSearch ()
300
300
return
301
301
}
0 commit comments